#include <bits/stdc++.h>
using namespace std;
const int MAX = 2550;
const int INF = 1e9;
char arr[MAX][MAX];
int sum[MAX][MAX];
int main() {
  int N, M;
  scanf("%d %d", &N, &M);
  for (int i = 1; i <= N; i++) {
    scanf("%s", arr[i] + 1);
  }
  for (int i = 1; i <= N; i++) {
    for (int j = 1; j <= M; j++) {
      sum[i][j] = sum[i - 1][j] + sum[i][j - 1] - sum[i - 1][j - 1];
      if (arr[i][j] == '1') {
        sum[i][j]++;
      }
    }
  }
  int ans = INF;
  for (int i = 2; i <= max(N, M); i++) {
    int s = 0;
    for (int j = 0;; j++) {
      int sx = (j * i) + 1;
      if (sx > N) {
        break;
      }
      for (int k = 0;; k++) {
        int sy = (k * i) + 1;
        if (sy > M) {
          break;
        }
        int ey = min(M, (k + 1) * i);
        int ex = min(N, (j + 1) * i);
        int c = sum[ex][ey] + sum[sx - 1][sy - 1] - sum[sx - 1][ey] -
                sum[ex][sy - 1];
        s += min(i * i - c, c);
      }
    }
    ans = min(ans, s);
  }
  printf("%d\n", ans);
  return 0;
}
