#include <bits\stdc++.h>

#define FAST {ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);}
#define in insert
#define er erase
#define pb push_back
#define fi first
#define se second
#define ll long long
#define mp make_pair
#define maxn 50005

/*
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;

#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
*/

ll a[1505][1505];

using namespace std;

int svinule(ll a[][1505], int m){
    for(int i = 1; i <= m; i++){
        if(a[1][i] == 1) return 0;
    }
    return 1;
}

int kolikokeceva(ll a[][1505], int m){
    ll rez = 0;
    for(int i = 1; i <= m; i++){
        if(a[1][i] % 2 == 1) rez++;
    }
    return rez;
}

void podelisve(ll a[][1505], int m){
    for(int i = 1; i <= m; i++){
        a[1][i] /= 2;
    }
}

int main()
{
    FAST

    ll n, m;
    cin >> n >> m;
    for(int i = 1; i <= n; i++){
        for(int j = 1; j <= m; j++){
            cin >> a[i][j];
        }
    }
    if(n == 1){
        ll finalni = 0;
        ll mnozenje = 1;
        while(!svinule(a, m)){
            ll s = kolikokeceva(a, m);
            finalni = mnozenje * min(s, m - s);
            podelisve(a, m);
            mnozenje *= 2;
        }
        cout << finalni << endl;
    }
    else if(n == 2 && m == 1){
        ll rez = 0;
        ll mnozenje = 1;
        ll x = a[1][1];
        ll y = a[2][1];
        while(x > 0 || y > 0){
            if((x % 2) != (y % 2)){
                rez += mnozenje;
            }
            mnozenje *= 2;
            x /= 2;
            y /= 2;
        }
        cout << rez << endl;
    }
    else{
        cout << "420" << endl;
    }
    return 0;
}