#include <bits/stdc++.h>
using namespace std;
void addmod(int &a, long long b) {
  a = (a + b);
  if (a >= 1000000007) a -= 1000000007;
}
void mulmod(int &a, long long b) { a = (a * b) % 1000000007; }
template <class T>
bool domin(T &a, const T &b) {
  return a > b ? a = b, 1 : 0;
}
template <class T>
bool domax(T &a, const T &b) {
  return a < b ? a = b, 1 : 0;
}
int gi() {
  int a;
  scanf("%d", &a);
  return a;
}
long long gll() {
  long long a;
  scanf("%lld", &a);
  return a;
}
int main() {
  int n = gi(), m = gi(), ans = 1000000007;
  vector<vector<int> > a(5001, vector<int>(5001, 0));
  char *s;
  s = new char[2600];
  for (int i = 0; i < n; i++) {
    scanf("%s", s);
    for (int j = 0; j < 5001; j++) {
      if (j < m && s[j] == '1') a[i][j] = 1;
      a[i][j] += (j > 0 ? a[i][j - 1] : 0);
    }
  }
  for (int k = 2; k < max(n, m); k++) {
    int ri, ta = 0, tk = k * k;
    for (ri = 0; ri < n; ri += k) {
      vector<int> cl(5001, 0);
      int ix = 0;
      for (int ti = ri; ti < ri + k; ti++) {
        ix = 0;
        for (int ci = 0; ci < m; ci += k, ix++) {
          cl[ix] += a[ti][ci + k - 1] - (ci > 0 ? a[ti][ci - 1] : 0);
        }
      }
      for (int ixi = 0; ixi <= ix; ixi++) {
        ta += min(cl[ixi], tk - cl[ixi]);
      }
    }
    domin(ans, ta);
  }
  cout << ans << endl;
  return 0;
}
