program task_e; {$APPTYPE CONSOLE} uses SysUtils; var n,m,i,ans,j:longint; s1,s2:array[1..200005] of ansistring; b:boolean; s:ansistring; c:char; f:text; begin assign(f,'repair.in'); reset(f); readln(f,n,m); for i:=1 to n do begin for j:=1 to m do begin read(f,c); s1[j]:=s1[j]+c; end; readln(f); end; for i:=1 to n do begin for j:=1 to m do begin read(f,c); s2[j]:=s2[j]+c; end; readln(f); end; close(f); j:=1; for i:=m+1 to 2*m do begin s1[i]:=s1[j]; j:=j+1; end; for i:=1 to m do begin b:=true; for j:=1 to m do begin if (s2[j]<>s1[j+i-1]) then begin b:=false; break; end; end; if (b) then begin ans:=i-1; break; end; end; assign(f,'repair.out'); rewrite(f); writeln(f,ans); close(f); end.