import java.io.*;
import java.util.*;

public class cage_md_assert implements Runnable {
	final int[] dx = new int[]{1, 0, -1, 0};
	final int[] dy = new int[]{0, 1, 0, -1};
	
	class Figure {
		int hei, wid;
		boolean[][] a;
		
		public Figure(boolean[][] a) {
			this.a = a;
			hei = a.length;
			wid = a[0].length;
		}
		
		public Figure(Scanner in) {
			String s = in.nextLine();
			Scanner sc = new Scanner(s);
			hei = sc.nextInt();
			wid = sc.nextInt();
			assert s.equals(hei + " " + wid) : "bad spacing in line <" + s + ">";
			assert 1 <= hei && hei <= 10 : "bad height = " + hei;
			assert 1 <= wid && wid <= 10 : "bad width = " + wid;
			a = new boolean[hei][wid];
			for (int i = 0; i < hei; i++) {
				s = in.nextLine();
				assert s.length() == wid : "wrong width of line";
				for (int j = 0; j < wid; j++) {
					assert ".*".contains("" + s.charAt(j)) : "invalid symbol";
					a[i][j] = s.charAt(j) == '*';
				}
			}
			boolean first = true;
			mark = new boolean[hei][wid];
			for (int i = 0; i < hei; i++) {
				for (int j = 0; j < wid; j++) {
					if (a[i][j]) {
						if (first) {
							dfsFigure(i, j);
						} else {
							assert mark[i][j] : "non-connected figure";
						}
						if (i + 1 < hei && j + 1 < wid && a[i + 1][j + 1]) {
							if (!a[i][j + 1] && !a[i + 1][j])
								throw new RuntimeException("bad square 2*2");
						}
						if (i + 1 < hei && j - 1 >= 0 && a[i + 1][j - 1]) {
							if (!a[i][j - 1] && !a[i + 1][j])
								throw new RuntimeException("bad square 2*2");
						}
					}
				}
			}
		}
		
		private void dfsFigure(int i, int j) {
			if (i < 0 || j < 0 || i >= hei || j >= wid || !a[i][j] || mark[i][j])
				return;
			mark[i][j] = true;
			for (int d = 0; d < 4; d++) {
				dfsFigure(i + dx[d], j + dy[d]);
			}
		}

		boolean[][] mark;
		boolean freedom;
		int area;
		
		public int maxHollow() {
			mark = new boolean[hei][wid];
			int res = -1;
			for (int i = 0; i < hei; i++) {
				for (int j = 0; j < wid; j++) {
					if (!a[i][j] && !mark[i][j]) {
						freedom = false;
						area = 0;
						dfs(i, j);
						if (!freedom)
							res = Math.max(res, area);
					}
				}
			}
			return res;
		}

		private void dfs(int i, int j) {
			if (i < 0 || j < 0 || i >= hei || j >= wid) {
				freedom = true;
				return;
			}
			if (a[i][j] || mark[i][j])
				return;
			mark[i][j] = true;
			area++;
			for (int d = 0; d < 4; d++) {
				dfs(i + dx[d], j + dy[d]);
			}
		}

		public Figure superpose(Figure b, int dx, int dy) {
			int ax = 0, bx = 0;
			if (dx < 0) {
				ax = -dx;
			} else {
				bx = dx;
			}
			int x = Math.max(ax + hei, bx + b.hei);
			int ay = 0, by = 0;
			if (dy < 0) {
				ay = -dy;
			} else {
				by = dy;
			}
			int y = Math.max(ay + wid, by + b.wid);
			boolean[][] c = new boolean[x][y];
			for (int i = 0; i < hei; i++) {
				for (int j = 0; j < wid; j++) {
					c[ax + i][ay + j] = a[i][j];
				}
			}
			for (int i = 0; i < b.hei; i++) {
				for (int j = 0; j < b.wid; j++) {
					if (b.a[i][j]) {
						if (c[bx + i][by + j]) {
							return null;
						}
						c[bx + i][by + j] = true;
					}
				}
			}
			return new Figure(c);
		}
		
		public Figure flip() {
			boolean[][] b = new boolean[hei][wid];
			for (int i = 0; i < hei; i++) {
				for (int j = 0; j < wid; j++) {
					b[i][wid - 1 - j] = a[i][j];
				}
			}
			return new Figure(b);
		}
		
		public Figure rotate() {
			boolean[][] b = new boolean[wid][hei];
			for (int i = 0; i < hei; i++) {
				for (int j = 0; j < wid; j++) {
					b[wid - 1 - j][i] = a[i][j];
				}
			}
			return new Figure(b);
		}
		
		public Figure transform(int t) {
			Figure f = this;
			if (t >= 4) {
				f = f.flip();
				t -= 4;
			}
			for (int i = 0; i < t; i++)
				f = f.rotate();
			return f;
		}
	}
	
	private Scanner in;
	private PrintWriter out;

	public void run() {
		try {
			solve();
		} catch (IOException e) {
			e.printStackTrace();
			System.exit(1);
		}
	}

	private void solve() throws IOException {
		Locale.setDefault(Locale.US);
		in = new Scanner(new FileReader("cage.in"));
		out = new PrintWriter("cage.out");
		Figure a = new Figure(in);
		Figure b0 = new Figure(in);
		int ans = 0;
		for (int t = 0; t < 8; t++) {
			Figure b = b0.transform(t);
			for (int dx = -b.hei; dx <= a.hei; dx++) {
				for (int dy = -b.wid; dy <= a.wid; dy++) {
					Figure c = a.superpose(b, dx, dy);
					if (c == null)
						continue;
					int cage = c.maxHollow();
					ans = Math.max(ans, cage);
				}
			}
		}
		out.println(ans);
		in.close();
		out.close();
	}

	public static void main(String[] args) {
		new Thread(new cage_md_assert()).start();
	}
}
