#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main()
{
    freopen("video.in", "r", stdin);
    freopen("video.out", "w", stdout);
    int n, m, ed = 0, dv = 0, i, j, ans = 0, vl, kr, ost;
    char c;
    cin >> n >> m;
    for (i = 0; i < n; i++)
    {
        scanf("\n");
        for (j = 0; j < m; j++)
        {
            scanf("%c", &c);
            if (c == '1')
                ed++;
            else
                dv++;
        }
    }

    if (ed < dv)
        swap(ed, dv);
    if (dv == 0)
    {
        cout << (n - 1) * (m - 1) << endl;
        return 0;
    }

    for (i = 1; i <= min(ed, m); i++)
    {
        if (i * n < ed)
            continue;
        kr = ed / i;
        if (kr > 0)
            vl = (i - 1) * (kr - 1);
        ost = ed % i;
        if ((ost > 0) && (kr > 0))
            vl += ost - 1;
        //cout << vl << endl;
        if ((m - i > 0) && (kr > 1))
            vl += (m - i - 1) * (kr - 1);
        //cout << vl << endl;
        if (ost == 0)
        {
            if (n - kr > 0)
                vl += (m - 1) * (n - kr - 1);
        }
        else
        {
            if (n - kr - 1 > 0)
            {
                vl += (m - 1) * (n - kr - 2);
                vl += (m - ost - 1);
            }
            if (kr > 0)
                vl += max(0, min(m - ost - 1, m - i - 1));
        }
        //cout << vl << ' ' << i << endl;
        ans = max(ans, vl);
    }

    cout << ans << endl;
    return 0;
}
/*

2 4
1221
1221

3 2
22
22
22

3 3
111
121
111

*/
