#include <bits/stdc++.h>

using namespace std;

int main()
{
    ios::sync_with_stdio(false);
    cin.tie();

    int n,m,br=0;
    bool prom=true;
    cin>>n>>m;
    int a[n][m];
    for(int i=0;i<n;i++){
        for(int j=0;j<m;j++){
            cin>>a[i][j];
            if(a[i][j]!=1 || a[i][j]!=0){
                prom=false;
            }
            br+=a[i][j];
        }
    }
    if(prom&&(n==1||m==1)){
        if(n*m/2<br)
            cout<<br;
        else cout<<n*m/2;
    }
    else if(prom){
        if(n*m/2==br){
            if(n*m%2==0)
                cout<<1;
            else cout<<0;
        }
        else if(n*m/2<br)cout<<br;
        else cout<<n*m/2;
    }
    cout<<1;

    return 0;
}