var
a,b,c,d:array [1..10,1..10] of char;
i,j,t,n:longint;
function pd:boolean;
var
i,j:longint;
begin
pd:=true;
for i:=1 to n do
for j:=1 to n do
if c[i,j]<>b[i,j] then pd:=false;
end;
function xz(x:longint):boolean;
var
t,i,j:longint;
begin
for t:=1 to x do
begin
d:=c;
for i:=1 to n do
for j:=1 to n do
c[j,n-i+1]:=d[i,j];
end;
xz:=pd;
end;
procedure fs;
var
i,j:longint;
begin
for i:=1 to n do
for j:=1 to n do
c[i,j]:=a[i,n+1-j];
end;
begin
readln(n);
for i:=1 to n do
begin
for j:=1 to n-1 do
read(a[i,j]);
readln(a[i,n]);
end;
for i:=1 to n do
begin
for j:=1 to n-1 do
read(b[i,j]);
readln(b[i,n]);
end;
for t:=1 to 7 do
case t of
1,2,3:begin c:=a; if xz(t) then
begin writeln(t); exit; end; end;
4:begin fs; if pd then begin writeln(4); exit; end; end;
5:begin fs; if xz(1) then begin writeln(5); exit; end;
fs; if xz(2) then begin writeln(5); exit; end;
fs; if xz(3) then begin writeln(5); exit; end; end;
6:begin c:=a; if pd then begin writeln(6); exit; end; end;
7:writeln(7);
end;
end.