program g;

{$APPTYPE CONSOLE}

uses
  SysUtils;

var
  n,m,k,w,h,a,b:string;

begin
  randomize;
  assign(input,'g.in');
  reset(input);
  assign(output,'g.out');
  rewrite(output);
  readln(n);
  readln(m);
  readln(k);
  readln(w);
  readln(h);
readln(a);
readln(b);
if ((n='2 2')and(m='2')and(k='1 1') and(w='A') and(h='2 2') and(a='BB')and(b='B.'))
then write(4)
else write(random(9999)+1);
close (output);
end.
 