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

public class main {
    String fileName = "video";
    boolean check(int i, int j){
    	int y = a[i][j] * a[i][(j + 1) % m] * a[(i + 1) % n][j] * a[(i + 1) % n][(j + 1) % m];
    	if (y == 1 || y==16)
    		return true;
    	return false;
    }
    int n;
    int m;
    int[][] a;
    public void solve() throws IOException {
        n = nextInt();
        m = nextInt();
       a = new int[n][m];
        for (int i = 0; i < a.length; i++) {
			char[] s = nextToken().toCharArray();
			for (int j = 0; j < m; j++){
				a[i][j] = (int)s[j] - (int)'0';
			}
		}
        long[] dp = new long[m];
        long maxx = 0;
        for (int i = 0; i < m; i++){
        	int k1 = 0;
        	int k2 = 0;
        	for (int j = 0; j < n - 1; j++){
        		if (check(j, i)){
        			k1 += 1;
        		}
        		if (check(j, (i + m - 1) % m)){
        			k2 += 1;
        		}
        	}
        	if (i == 0)
        		dp[i] = k2 - k1;
        	else
        		dp[i] = k2 - k1 + dp[i - 1];
        	maxx = Math.max(maxx, dp[i]);
        }
//        for (int i = 0; i < m; i++){
//        	out.print(dp[i] + " ");
//        }
//        out.println();
        for (int i = 0; i < n; i++){
        	for (int j = 0; j < m; j++){
        		if (check((n + n - 2 - i) % n, j)){
        			dp[j]--;
        		}
        		if (check((n - 1 - i) % n, j)){
        			dp[j]++;
        		}
        		if (check((n + n - 2 - i) % n, (j - 1 + m) % m)){
        			dp[j]--;
        		}
        		if (check((n - 1 - i) % n, (j - 1 + m) % m)){
        			dp[j]++;
        		}
        		maxx = Math.max(maxx, dp[j]);
        	}
//        	for (int i1 = 0; i1 < m; i1++){
//            	out.print(dp[i1] + " ");
//            }
//            out.println();
        }
        long result = 0;
        for(int i = 0; i < n - 1; i++){
        	for(int j = 0; j < m - 1; j++){
        		if (check(i, j))
        			result++;
        	}
        }
        out.println(result + maxx);
    }

    public void run() {
        try {
            br = new BufferedReader(new FileReader(fileName + ".in")); 
            out = new PrintWriter(fileName + ".out");

            solve();

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

    BufferedReader br;
    StringTokenizer in;
    PrintWriter out;

    public String nextToken() throws IOException {
        while (in == null || !in.hasMoreTokens()) {
            in = new StringTokenizer(br.readLine());
        }
        return in.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 main().run();
    }

}