program Project2; uses SysUtils; var n,m,i,j,m1,k,rec1:longint; a:array[1..2,1..20,1..100000]of boolean; ch:char; t,b:boolean; procedure rec(j:longint); var m1,i,j1:longint; begin m1:=m; t:=true; j1:=j; while t do begin t:=true; for i:=1 to n do begin if a[1,i,m1]<>a[2,i,j1]then begin t:=false; break; end; end; if t then begin dec(m1); end else rec(j+1); if m1=0 then begin if b then begin rec1:=m-j; b:=false end; break; end; if j1=1 then j1:=m else dec(j1); end; end; begin b:=true; assign(input,'repair.in'); reset(input); assign(output,'repair.out'); rewrite(output); readln(n,m); for k:=1 to 2 do for i:=1 to n do begin for j:=1 to m do begin read(ch); if ch='.' then a[k,i,j]:=true; end; readln; end; close(input); rec(1); writeln(rec1); close(output); end.