#include "iostream"
#include "algorithm"
#include "cmath"
#include "vector"
using namespace std;
#define forn(i, n) for (int i = 0; i < (n); i++)
#define forns(i, s, n) for (int i = s; i < (n); i++)
#define int long long
signed main() {
    int n, m;
    cin >> n >> m;
    vector<int> valka(n + m);
    for (int i = 0; i < n; ++i) {
        for (int j = 0; j < m; ++ j) {
            int x;
            cin >> x;
            valka[i + j] ^= x;
        }
    }
    vector<int> onecnt(31);
    for (int i = 0; i < n + m; ++i) {
        for (int j = 0; j < 31; ++ j) {
            if (valka[i] & (1 << j)) {
                onecnt[j]++;
            }
        }
    }
    int res = 0;
    for (int i = 0; i < 31; ++i) {
        onecnt[i] = min(onecnt[i], n + m - 1 - onecnt[i]);
        res += onecnt[i] * (1ll << i);
    }
    cout << res << '\n';
}