#include <iostream>
#include <vector>

using namespace std;

int main() {
    int n, m;
    cin >> n >> m;
    vector<vector<int>> init(n, vector<int>(m));
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < m; j++) {
            cin >> init[i][j];
        }
    }
    int minSum = -1;
    for (int x = 0; x < (1 << (n + m - 1)); x++) {
        vector<vector<int>> res(n, vector<int>(m));
        res[0][0] = init[0][0] ^ x;
        for (int i = 1; i < n; i++) {
            res[i][0] = init[i][0] ^ x;
        }
        for (int j = 1; j < m; j++) {
            res[0][j] = init[0][j] ^ x;
        }
        for (int i = 1; i < n; i++) {
            for (int j = 1; j < m; j++) {
                res[i][j] = init[i][j] ^ x;
            }
        }
        int sum = 0;
        for (int i = 0; i < n; i++) {
            for (int j = 0; j < m; j++) {
                sum += res[i][j];
            }
        }
        minSum = min(minSum, sum);
    }
    cout << minSum << endl;
    return 0;
}