#include <bits/stdc++.h>
#define fr(i, n) for (int i = 0; i < n; i++)
#define frab(i, a, b) for (int i = a; i < b; i++)
#define pb push_back
#define mp make_pair

using namespace std;

typedef long long ll;
typedef long double ld;

const int N = 1e3 + 1;
const int INF = 2e9 + 1;

char a[N][N];

int main() {
    freopen("video.in", "r", stdin);
    freopen("video.out", "w", stdout);
    int n, m;
    cin >> n >> m;
    int c1 = 0, c2 = 0;
    fr(i, n)
        fr(j, m) {
            cin >> a[i][j];
            if (a[i][j] == '1')
                c1++;
            else
                c2++;
        }
    if (c1 > c2)
        swap(c1, c2);
    int x = c1;
    int ans = INF;
    if (x % n == 0)
        ans = min(ans, n - 1);
    if (x % m == 0)
        ans = min(ans, m - 1);
    frab(i, 1, x + 1) {
        int j1 = x / i;
        int i1 = i;
        if (min(i1, j1) <= min(n, m) && max(i1, j1) <= max(n, m)) {
            if (i1 * j1 == x)
                ans = min(ans, i1 + j1 - 1);
            else
                ans = min(ans, i1 + j1);
        }
    }

    ans = min(ans, n);
    ans = min(ans, m);
    if (x == 0)
        ans = 0;
    //cout << ans << endl;
    cout << (n - 1) * (m - 1) - ans;
}
