#include <bits/stdc++.h>
#pragma GCC optimize("O2")
#pragma GCC optimize("unroll-loops")
using namespace std;
const int MAX = 1e5 + 5;
const long long MAX2 = 2505;
const long long MOD = 1000000007;
const long long MOD2 = 1000005329;
const long long INF = 2e15;
const int dr[] = {1, 0, -1, 0, 1, 1, -1, -1, 0};
const int dc[] = {0, 1, 0, -1, 1, -1, 1, -1, 0};
const double pi = acos(-1);
const double EPS = 1e-9;
const int block = 555;
int n, m, x[MAX], y, id, a, b, cnt[MAX * 20][22], ans, res, pre[25];
bool st[MAX * 20];
vector<int> lvl[25], v[MAX * 20];
char c;
void f(int z, int le, int ri, int par) {
  if (!z) {
    cnt[par][st[par]] = ri - le + 1;
    return;
  }
  int mid, res = ri + 1;
  a = le, b = ri, y = 1 << z;
  while (a <= b) {
    mid = a + b >> 1;
    if (x[mid] & y)
      res = mid, b = mid - 1;
    else
      a = mid + 1;
  }
  if (res != le)
    lvl[z].push_back(++id), v[par].push_back(id), f(z - 1, le, res - 1, id);
  if (res <= ri)
    st[++id] = 1, lvl[z].push_back(id), v[par].push_back(id),
    f(z - 1, res, ri, id);
  return;
}
void bf(int z, bool q) {
  if (z > n) {
    if (q) return;
    res = 0;
    for (int i : v[0]) {
      for (int j = 0; j <= n; ++j) {
        res += cnt[i][j] * pre[j];
      }
    }
    ans = min(ans, res);
    return;
  }
  if (z == 1) {
    if (q)
      for (int i : lvl[z]) cnt[i][0] ^= cnt[i][1] ^= cnt[i][0] ^= cnt[i][1];
  } else {
    for (int i : lvl[z]) {
      for (int j = 0; j <= z; ++j) cnt[i][j] = 0;
      if (q ^ st[i]) {
        for (int k : v[i]) {
          for (int j = 0; j < z; ++j) cnt[i][j + 1] += cnt[k][j];
        }
      } else {
        for (int k : v[i]) {
          for (int j = 0; j < z; ++j) cnt[i][j] += cnt[k][j];
        }
      }
    }
  }
  bf(z + 1, 0);
  bf(z + 1, 1);
  return;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  cin >> n >> m;
  for (int i = 0; i <= n; ++i) pre[i] = min(i, n - i);
  for (int i = 1; i <= n; ++i) {
    y = 1 << i;
    for (int j = 1; j <= m; ++j) {
      cin >> c;
      if (c == '1') x[j] |= y;
    }
  }
  sort(x + 1, x + 1 + m);
  f(n, 1, m, 0);
  ans = MOD;
  bf(0, 0);
  cout << ans << '\n';
  return 0;
}
