var
	n, m, i, j, a, b, x, y, count, last, ans : integer;
	flat : array[1..50, 1..50] of integer;
	want, light : array[1..50, 1..50] of char;
begin
	assign(input, 'crazy.in');
	reset(input);
	assign(output, 'crazy.out');
	rewrite(output);
	readln(n, m);
	if (n < 1) or (n > 50) then halt(1);
	if (m < 1) or (m > 50) then halt(1);
	for i := 1 to n do begin
		for j := 1 to m do begin
			read(flat[i][j]);
		end;
		readln;
	end;
	for i := 1 to n do begin
		for j := 1 to m do begin
			read(light[i][j]);
		end;
		readln;
	end;
	readln(a, b);
	if (a < 1) or (a > n) then halt(1);
	if (b < 1) or (b > m) then halt(1);
	for i := 1 to a do begin
		for j := 1 to b do begin
			read(want[i][j]);
		end;
		readln;
	end;
	ans := a * b;
	for i := 1 to n - a + 1 do begin
		for j := 1 to m - b + 1 do begin
			count := 0;
			last := -1;
			for x := 1 to a do begin
				for y := 1 to b do begin
					if light[i + x][j + y] <> want[x][y] then begin
						if flat[i + x][j + y] <> last then begin
							inc(count);
							last := flat[i + x][j + y];
						end;
					end;
				end;
			end;
			if count < ans then begin
				ans := count;
			end;
		end;
	end;
	writeln(ans);	
	close(input);
	close(output);
end.