#include <bits/stdc++.h>
using namespace std;
int aces[5100][5100];
int n, m, kat, ans;
int bits[5100][5100];
int insq(int i, int j, int k) {
  int n = aces[i + k - 1][j + k - 1] - aces[i + k - 1][j - 1] -
          aces[i - 1][j + k - 1] + aces[i - 1][j - 1];
  return n;
}
int main() {
  scanf("%d %d", &n, &m);
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= m; j++) {
      scanf("%1d", &bits[i][j]);
    }
  }
  for (int i = 1; i <= 5050; i++) {
    for (int j = 1; j <= 5050; j++) {
      aces[i][j] =
          aces[i - 1][j] + aces[i][j - 1] - aces[i - 1][j - 1] + bits[i][j];
    }
  }
  ans = n * m;
  for (int k = 2; k <= max(m, n); k++) {
    kat = 0;
    for (int i = 1; i <= n; i = i + k) {
      for (int j = 1; j <= m; j = j + k) {
        int mol = insq(i, j, k);
        kat += min(mol, k * k - mol);
      }
    }
    ans = min(kat, ans);
  }
  printf("%d", ans);
  return 0;
}
