var a,b:array[1..100] of string; n,m,i,j,k:integer; begin readln(n,m); for i:=1 to n do readln(a[i]); readln; { пропуск пустой строки } for i:=1 to n do readln(b[i]); k:=0; for i:=1 to n do for j:=1 to m do if a[i][j]=b[i][j] then inc(k); writeln(k); end.