#include <bits/stdc++.h>
#define ll long long
#define ld long double
#define sp ' '
#define en '\n'
#define smin(a, b) a = min(a, b)
#define smax(a, b) a = max(a, b)
using namespace std;
const int N = 1500 + 2;
const int inf = 2e9;
int a[N][N];
int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int n, m;
    cin >> n >> m;
    for (int i = 1; i <= n; i++) {
        for (int j = 1; j <= m; j++) {
            cin >> a[i][j];
        }
    }
    ll ans = 0;
    for (int z = 0; z < 30; z++) {
        int sum = 0;
        for (int j = 1; j <= m; j++) if (a[1][j] & (1 << z)) sum++;
        ans += (ll) (1LL << z) * min(sum, m - sum);
    }
    cout << ans << en;
    return 0;
}