#include <bits/stdc++.h>
using namespace std;
char fi[5005][5005];
int ps[5005][5005];
int n, m;
int main() {
  for (int i = 0; i <= 5000; i++)
    for (int j = 0; j <= 5000; j++) fi[i][j] = '0';
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= n; i++) {
    getchar();
    for (int j = 1; j <= m; j++) {
      scanf("%c", &fi[i][j]);
    }
  }
  for (int i = 1; i <= 5000; i++) {
    for (int j = 1; j <= 5000; j++) {
      ps[i][j] = fi[i][j] - '0';
      ps[i][j] += ps[i - 1][j];
      ps[i][j] += ps[i][j - 1];
      ps[i][j] -= ps[i - 1][j - 1];
    }
  }
  int ans = 6000 * 6000;
  for (int k = 2; k <= 2500; k++) {
    int tmp = 0;
    for (int i = k; i <= 5000; i += k) {
      for (int j = k; j <= 5000; j += k) {
        int lala = ps[i][j] - ps[i - k][j] - ps[i][j - k] + ps[i - k][j - k];
        tmp += min(lala, k * k - lala);
      }
    }
    ans = min(ans, tmp);
  }
  printf("%d\n", ans);
  return 0;
}
