#include <bits/stdc++.h>
char f[5100][5100];
int n, m, dp[5100][5100];
char get(int i, int j) {
  if (i < n && j < m) return f[i][j];
  return '0';
}
void init() {
  for (int i = 0; i < 5100; i++) {
    int prev = 0;
    for (int j = 0; j < 5100; j++) {
      int t = get(i, j) - '0';
      dp[i][j] = prev + t;
      prev = dp[i][j];
    }
  }
}
int ask_line(int line, int l, int r) {
  return l > 0 ? dp[line][r] - dp[line][l - 1] : dp[line][r];
}
int ask(int ii, int jj, int xx, int yy) {
  int result = 0;
  for (int l = ii; l <= xx; l++) result += ask_line(l, jj, yy);
  return result;
}
int test(int ii, int jj, int xx, int yy) {
  int ones = ask(ii, jj, xx, yy);
  int all = (xx - ii + 1) * (yy - jj + 1);
  return std::min(ones, all - ones);
}
int test_value(int k) {
  int result = 0;
  for (int i = 0; i < n; i += k) {
    for (int j = 0; j < m; j += k) {
      int x = i + k - 1, y = j + k - 1;
      result += test(i, j, x, y);
    }
  }
  return result;
}
int main() {
  scanf("%d%d", &n, &m);
  for (int i = 0; i < n; i++) scanf("%s", f[i]);
  init();
  int ans = 2000000000;
  for (int k = 2; k <= std::max(n, m); k++) {
    ans = std::min(ans, test_value(k));
  }
  printf("%d\n", ans);
}
