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

public class A {
    String fileName = "video";

    public void solve() throws IOException {
    	int n = nextInt();
    	int m = nextInt();
    	int sum = 0, max = 0;
    	int[] a = new int[n], b = new int[m];
    	boolean[][] c = new boolean[n][m], d = new boolean[n][m];
    	for (int i = 0; i < n; i++) {
			char[] s = nextToken().toCharArray();
			for (int j = 0; j < s.length; j++) {
				c[i][j] = s[j] == '2';
			}
		}
    	for (int i = 0; i < n; i++) {
			for (int j = 0; j < m; j++) {
				d[i][j] =	(c[i][j] == c[i][(j + 1) % m]) && (c[i][j] == c[(i + 1) % n][j]) &&
							(c[i][j] == c[(i + 1) % n][(j + 1) % m]);
			}
		}
    	for (int i = 0; i < n; i++) {
			for (int j = 0; j < m; j++) {
				a[i] += d[i][j] ? 1 : 0;
				b[j] += d[i][j] ? 1 : 0;
				sum  += d[i][j] ? 1 : 0;
			}
		}
    	for (int i = 0; i < n; i++) {
			for (int j = 0; j < m; j++) {
				max = Math.max(max, sum - a[i] - b[j] + (d[i][j] ? 1 : 0));
			}
		}
    	out.println(max);
    }

    public void run() {
    	boolean test = false;
        try {
        	if (test) {
        		in = new BufferedReader(new InputStreamReader(System.in));
        		out = new PrintWriter(System.out);
        	} else {
        		in = new BufferedReader(new FileReader(fileName + ".in"));
        		out = new PrintWriter(fileName + ".out");
        	}

            solve();

            out.close();
            in.close();
        } catch (IOException e) {
            e.printStackTrace();
            System.exit(1);
        }
    }

    BufferedReader in;
    StringTokenizer st;
    PrintWriter out;

    public String nextToken() throws IOException {
        while (st == null || !st.hasMoreTokens()) {
            st = new StringTokenizer(in.readLine());
        }
        return st.nextToken();
    }

    public int nextInt() throws IOException {
        return Integer.parseInt(nextToken());
    }

    public double nextDouble() throws IOException {
        return Double.parseDouble(nextToken());
    }

    public long nextLong() throws IOException {
        return Long.parseLong(nextToken());
    }

    public static void main(String[] args) throws IOException {
        Locale.setDefault(Locale.US);
        new A().run();
    }

}