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

public class cage_gk_5 {
    static final int FAIL_ON = 5;

    static Scanner in;
    static PrintWriter out;

    static final int[] DX = new int[]{0, 0, -1, 1};
    static final int[] DY = new int[]{-1, 1, 0, 0};

    char[][] read () {
        int n = in.nextInt();
        int m = in.nextInt();
        in.nextLine();

        char[][] a = new char[n][m];

        for (int i = 0; i < a.length; i++) {
            a[i] = in.nextLine().toCharArray();
            assert(a[i].length == m);
        }
        return a;
    }

    char[][] t(char[][] a) {
        char[][] b = new char[a[0].length][a.length];
        for (int i = 0; i < a.length; i++) {
            for (int j = 0; j < a[i].length; j++) {
                b[j][i] = a[i][j];
            }
        }
        return b;
    }

    char[][] f(char[][] a) {
        char[][] b = new char[a.length][a[0].length];
        for (int i = 0; i < a.length; i++) {
            for (int j = 0; j < a[i].length; j++) {
                b[a.length - i - 1][j] = a[i][j];
            }
        }
        return b;
    }

    int fill(char[][] c, int i, int j) {
        if (i < 0 || c.length <= i || j < 0 || c[0].length <= j || c[i][j] != 0) {
            return 0;
        }
        c[i][j] = '.';
        int result = 1;
        for (int k = 0; k < 4; k++) {
            result += fill(c, i + DX[k], j + DY[k]);
        }
        return result;
    }

    void print(char[][] c) {
        for (int i = 0; i < c.length; i++) {
            System.out.println(new String(c[i]));
        }
        System.out.println();
    }

    int findRaster(char[][] c) {
        fill(c, 0, 0);
        int max = 0;
        for (int i = 0; i < c.length; i++) {
            for (int j = 0; j < c[0].length; j++) {
                max = Math.max(max, fill(c, i, j));
            }
        }

        return max;
    }

    boolean rasterize(char[][] c, char[][] a, int ai, int aj) {
        for (int i = 0; i < a.length; i++) {
            for (int j = 0; j < a[0].length; j++) {
                if (a[i][j] == '*') {
                    if (c[i + ai][j + aj] != 0) {
                        return false;
                    }
                    c[i + ai][j + aj] = a[i][j];
                }
            }
        }
        return true;
    }

    int findFixed(
        char[][] a, int ai, int aj,
        char[][] b, int bi, int bj
    ) {
        int n = Math.max(a.length + ai, b.length + bi) + 2;
        int m = Math.max(a[0].length + aj, b[0].length + bj) + 2;
        char[][] c = new char[n][m];
        rasterize(c, a, ai + 1, aj + 1);
        if (!rasterize(c, b, bi + 1, bj + 1)) {
            return 0;
        }
        return findRaster(c);
    }

    int findShift(char[][] a, char[][] b) {
        int max = 0;
        for (int i = -b.length; i <= a.length; i++) {
            for (int j = -b[0].length; j <= a[0].length; j++) {
                int mini = Math.min(0, i);
                int minj = Math.min(0, j);
                max = Math.max(max, findFixed(
                    a, 0 - mini, 0 - minj,
                    b, i - mini, j - minj
                ));
            }
        }
        return max;
    }

    int findAll(char[][] a, char[][] b) {
        int max = 0;
        for (int i = 0; i < 8; i++) {
            if (FAIL_ON != i) {
                max = Math.max(max, findShift(a, b));
            }
            if (i % 2 == 0) {
                b = t(b);
            } else {
                b = f(b);
            }
        }
        return max;
    }

    void run() {
        char[][] a = read();
        char[][] b = read();
        out.println(findAll(a, b));
    }

    public static void main(String[] args) throws IOException {
        in = new Scanner(new File("cage.in"));
        out = new PrintWriter("cage.out");

        while (in.hasNext()) {
            new cage_gk_5().run();
        }

        in.close();
        out.close();
    }
}