#include <bits/stdc++.h>

using namespace std;

string s[1000];
int c[2];


int main()
{
    ifstream cin("video.in");
    ofstream cout("video.out");
    int cnt = 1e9;
    int n, m;
    cin >> n >> m;
    for (int i = 0; i < n; i++){
        cin >> s[i];
        for (int j = 0; j < m; j++){
            c[s[i][j] - '0']++;
        }
    }

    if (m > n)
        swap(m, n);
    if (c[2] == 0){
        cout << (n - 1) *  (m - 1);
        return 0;
    }

    for (int i = 1; i < n + 1; i++){
        for (int j = 1; j < m + 1; j++){
            int cc = c[2];
            if (c[2] > i * j)
                continue;
            if (i + j - 1 > c[2])
                continue;

            int ans = i + j - 1;
            if (i == n)
                ans--;
            if (j == m)
                ans--;

            cc -= i + j - 1;
            if (j == m && i == n){
                int ii = 1, jj = 1;
                while (cc){
                    cc--;
                    if (jj == m - 1 || n == i - 1)
                        ans--;
                    if (jj == j - 1)
                        jj = 1, ii++;
                    else
                        jj++;
                }
            }

            if (j == m && i != n){
                int ii = 1, jj = 1;
                while (cc){
                    cc--;
                    if (jj == m - 1)
                        ans--;
                    if (jj == j - 1)
                        jj = 1, ii++;
                    else
                        jj++;
                }
            }

            if (j != m && i == n){
                int ii = 1, jj = 1;
                while (cc){
                    cc--;
                    if (ii == n - 1)
                        ans--;
                    if (ii == i - 1)
                        ii = 1, jj++;
                    else
                        ii++;
                }
            }

            cnt = min(ans, cnt);
        }
    }

    cout << (n - 1) * (m - 1) - cnt;
    return 0;
}
