#include <bits/stdc++.h>
using namespace std;
bool img[5001][5001];
int ones[5001][5001];
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  int n, m;
  cin >> n >> m;
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= m; j++) {
      char c;
      cin >> c;
      if (c == '0')
        img[i][j] = 0;
      else
        img[i][j] = 1;
    }
  }
  if (img[1][1]) ones[1][1] = 1;
  for (int i = 2; i < 5001; i++) {
    ones[i][1] = ones[i - 1][1];
    if (img[i][1]) ones[i][1]++;
  }
  for (int i = 2; i < 5001; i++) {
    ones[1][i] = ones[1][i - 1];
    if (img[1][i]) ones[1][i]++;
  }
  for (int i = 2; i < 5001; i++) {
    for (int j = 2; j < 5001; j++) {
      ones[i][j] = ones[i - 1][j] + ones[i][j - 1] - ones[i - 1][j - 1];
      if (img[i][j]) ones[i][j]++;
    }
  }
  int minn = n * m;
  for (int k = 2; k <= max(n, m); k++) {
    int ans = 0;
    for (int i = k; i < n + k; i += k) {
      for (int j = k; j < m + k; j += k) {
        ans += min(
            ones[i][j] - ones[i - k][j] - ones[i][j - k] + ones[i - k][j - k],
            (k * k) - (ones[i][j] - ones[i - k][j] - ones[i][j - k] +
                       ones[i - k][j - k]));
      }
    }
    minn = min(ans, minn);
  }
  cout << minn << "\n";
  return 0;
}
