#include <bits/stdc++.h>

#define ll long long

using namespace std;

void test1(ll arr[], int n) {

    ll x = 0;
    for(ll b = 0; b <= 30; b++) {
        int br = 0;
        for(int i = 0; i < n; i++)
            if(arr[i] & (1 << b))
                br++;
        if(br > n - br)
            x ^= (1 << b);
    }

    ll sum = 0;
    for(int i = 0; i < n; i++)
        sum += arr[i] ^ x;
    cout << sum << endl;
}

int main() {

    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);

    int n, m;
    cin >> n >> m;

    ll mat[n][m];
    for(int i = 0; i < n; i++)
        for(int j = 0; j < m; j++)
            cin >> mat[i][j];

    if(n == 1) {
        test1(mat[0], m);
        return 0;
    }

    if(m == 1) {
        ll arr[n];
        for(int i = 0; i < n; i++)
            arr[i] = mat[i][0];
        test1(arr, n);
        return 0;
    }

    ll A = mat[0][0], B = mat[0][1], C = mat[1][0], D = mat[1][1];
    ll x = 0, y = 0;
    for(ll b = 0; b <= 30; b++) {
        ll B1 = 0, B2 = 0, mn = A + B + C + D;
        for(ll b1 = 0; b1 < 2; b1++) {
            for(ll b2 = 0; b2 < 2; b2++) {
                ll sum = (A ^ (b1 << b) ^ (b2 << b))
                    + (B ^ (b1 << b))
                    + (C ^ (b2 << b))
                    + (D ^ (b1 << b) ^ (b2 << b));

                if(sum < mn) {
                    mn = sum;
                    B1 = b1;
                    B2 = b2;
                }
            }
        }
        x ^= B1 << b;
        y ^= B2 << b;
    }
    cout << (A ^ x ^ y) + (B ^ x) + (C ^ y) + (D ^ x ^ y) << endl;
    return 0;
}