#include <bits/stdc++.h>
using namespace std;

#define ios ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define ll long long
#define inf INT_MAX
#define llinf LLONG_MAX
#define mt make_tuple
#define mp make_pair
#define parll pair<ll,ll>
#define parii pair<int,int>
#define nzd __gcd
#define nzs(e1,e2) (e1/nzd(e1,e2))*e2
#define neparno(v) (v&1)
#define parno(v) (!neparno(v))
#define lowbit(v) (v&-v)
#define all(V) V.begin(),V.end()
#define fill(V,v) fill(all(V),v)
#define l_b(BRL,brl) lower_bound( BRL.begin(), BRL.end(), brl )-BRL.begin()-1
#define u_b(BRU,bru) upper_bound( BRU.begin(), BRU.end(), bru )-BRU.begin()
#define mod 1000000007
#define mxn 1502

ll q,n,m,A[mxn][mxn];

void Podzadatak2()
{
    ll rez = llinf;
    for ( ll k = 1; k <= m; k++ )
    {
        ll x = A[1][k];
        ll t = 0;
        for ( ll i = 1; i <= m; i++ )
        {
            t += (A[1][i]^x);
        }
        rez = min( rez, t );
    }
    cout << rez;
}

int main()
{
    ios;

    cin >> n >> m;
    ll suma = 0;
    for ( ll i = 1; i <= n; i++ )
    {
        for ( ll j = 1; j <= m; j++ )
        {
            cin >> A[i][j];
            suma += A[i][j];
        }
    }
    if ( n == 1 && m == 1 )
    {
        cout << "0\n";
        return 0;
    }
    if ( n == 1 && m <= 2 )
    {
        cout << suma-2*(A[1][1]&A[1][2]);
        return 0;
    }
    if ( n <= 2 && m == 1 )
    {
        cout << suma-2*(A[1][1]&A[2][1]);
        return 0;
    }
    if ( n == 1 )
    {
        Podzadatak2();
        return 0;
    }
    cout << "0\n";

    return 0;
}