#include <bits/stdc++.h>
using namespace std;
const int N = 5005;
int sum[N][N];
char st[N][N];
int main() {
  int n, m;
  scanf("%d %d", &n, &m);
  for (int i = 1; i <= n; i++) scanf("%s", st[i] + 1);
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= m; j++) {
      sum[i][j] = st[i][j] == '1';
    }
  }
  for (int i = 1; i <= n; i++) {
    for (int j = m; j >= 1; j--) {
      sum[i][j] += sum[i][j + 1];
    }
  }
  int ans = n * m;
  for (int i = 2; i <= min(n, m); i++) {
    int cnt = 1;
    int res = 0;
    while (cnt <= n) {
      for (int j = 1; j <= m; j += i) {
        int ret = 0;
        for (int k = cnt; k < cnt + i; k++) {
          ret += sum[k][j] - sum[k][j + i];
        }
        if (ret * 2 > i * i)
          res += (i * i - ret);
        else
          res += ret;
      }
      cnt += i;
    }
    ans = min(ans, res);
  }
  cout << ans << endl;
  return 0;
}
