#include <iostream>
#include <algorithm>
#include <fstream>
using namespace std;

int main()
{
    cin.tie(0);
    freopen("video.in","r",stdin);
    freopen ("video.out","w",stdout);
    int n,m;
    char c1;
    int ans;
    int ans1=0;
    int ans2=0;
    int i,j;
    scanf("%d %d/n",&n,&m);
    for (i=0;i<n;++i){
        for(j=0;j<m;++j){
            cin>>c1;

            if (c1=='2') {
                    ans2++;
            }
             else {
                    ans1++;
             }
        }
    }
    if (ans1<ans2) swap(ans1,ans2);
    int x2, x3;
    x2=min(n,m);
    x3=max(n,m);
    int q1;int q2=0;
    //cout<<ans1<<" "<<ans2<<endl;
    if (ans2==0) {q1=(n-1)*(m-1);} else{
        if (ans2<x2) {q1=n*m-x2-x3+1-ans2;} else{
            if (ans1%x2==0){
                q1=n*m-x2-x3+2-x2;
            }else{
                q1=n*m-x2-x3-x2+1;
            }
            if (ans1%x3==0){
                q2=n*m-x2-x3+2-x3;
            }else{
                q2=n*m-x2-x3-x3+1;
            }
        }

    }

    cout<<max(q1,q2);
    return 0;
}
