#include <bits/stdc++.h>

using namespace std;

mt19937 rng(42069);

using ll = long long;

int main() {
    int n, m;
    cin >> n >> m;
    vector<vector<int>> mat(n, vector<int>(m));

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

    if(n == 1) {
        ll ans = 0;
        for(int j = 0; j <= 30; ++j) {
            int ima = 0;
            for(int i = 0; i < m; ++i) {
                if((mat[0][i] >> j) & 1) ++ima;
            }

            if(m - ima < ima) {
                ima = m - ima;
            }

            ans += (1LL << j) * ima;
        }

        cout << ans << '\n';
        return 0;
    }

    auto gen = [&n, &m](vector<vector<int>> mat) {
        int x = 0, y = 0;

        while(x != n - 1 && y != m - 1) {
            mat[x][y] ^= 1;
            if(x == n - 1) {
                ++y;
            } else if (y == m - 1) {
                ++x;
            } else {
                int bruh = rng() % 2;
                if(bruh) ++x;
                else ++y;
            }
        }

        mat[x][y] ^= 1;

        return mat;
    };

    map<vector<vector<int>, int> vrednosti;

    auto generisiMoguce = [&](vector<vector<int>> mat) {
        set<vector<vector<int>> moguci;
        moguci.insert(mat);

        auto prvi = mat;

        int ans = INT_MAX;

        for(int i = 0; i < 100; ++i) {
            auto temp = gen(mat);

            int cnt = 0;

            for(auto z : temp) {
                for(auto y : z) {
                    cnt += y;
                }
            }
            ans = min(ans, cnt);
            moguci.insert(temp);
        }

        vrednost[prvi] = ans;
    };

    for(int mask = 0; mask < (1 << (n * m)); ++mask) {
        vector<int> nz;
        for(int i = 0; i < n * m; ++i) {
            nz.push_back((mask >> i) & 1);
        }

        vector<vector<int>> mat(n, vector<int>(m));

        int poka = 0;

        for(int i = 0; i < n; ++i) {
            for(int j = 0; j < m; ++j) {
                mat[i][j] = nz[poka];
                ++poka;
            }
        }

        generisiMoguce(mat);
    }

    ll ans = 0;

    for(int iter = 0; iter <= 30; ++iter) {
        vector<vector<int>> bruh(n, vector<int>(m));

        for(int i = 0; i < n; ++i) {
            for(int j = 0; j < m; ++j) {
                bruh[i][j] = (mat[i][j] >> iter) & 1;
            }
        }

        ans += vrednosti[bruh] * (1LL << iter);
    }

    cout << ans << '\n';
}