#include <bits/stdc++.h>
const int N = 2555;
char s[N][N];
int sum[N][N];
int main() {
  int n, m;
  while (~scanf("%d %d", &n, &m)) {
    memset(sum, 0, sizeof sum);
    for (int i = 1; i <= n; i++) {
      scanf("%s", s[i] + 1);
      for (int j = 1; j <= m; j++) {
        sum[i][j] =
            sum[i - 1][j] + sum[i][j - 1] + s[i][j] - '0' - sum[i - 1][j - 1];
      }
    }
    int l = std::max(n, m);
    int ans = 0x3f3f3f3f;
    for (int k = 2; k <= l; k++) {
      int tmp = 0;
      for (int i = 1; i <= n; i++) {
        for (int j = 1; j <= m; j++) {
          int t = sum[std::min(i * k, n)][std::min(j * k, m)] -
                  sum[(i - 1) * k][std::min(j * k, m)] -
                  sum[std::min(i * k, n)][(j - 1) * k] +
                  sum[(i - 1) * k][(j - 1) * k];
          tmp += std::min(t, k * k - t);
          if (j * k >= m) break;
        }
        if (i * k >= n) break;
      }
      ans = std::min(ans, tmp);
    }
    printf("%d\n", ans);
  }
  return 0;
}
