#include <bits/stdc++.h>
using namespace std;
int n, m, a[3000][3000], d[5002][5002];
string ch;
int cz;
int main() {
  cin >> n >> m;
  getline(cin, ch);
  for (int i = 1; i <= n; i++) {
    getline(cin, ch);
    for (int j = 1; j <= m; j++) {
      a[i][j] = ch[j - 1] - '0';
      d[i][j] = d[i - 1][j] + d[i][j - 1] + a[i][j] - d[i - 1][j - 1];
    }
  }
  cz = max(n, m) * 2 + 1;
  for (int i = 1; i <= cz; i++)
    for (int j = 1; j <= cz; j++)
      if (i > n || j > m) d[i][j] = d[i - 1][j] + d[i][j - 1] - d[i - 1][j - 1];
  int res = (1 << 30);
  for (int k = 2; k <= n; k++) {
    int na = n / k;
    if (n % k) na++;
    int ma = m / k;
    if (m % k) ma++;
    int cur = 0;
    for (int i = 1; i <= na; i++)
      for (int j = 1; j <= ma; j++) {
        int li = (i - 1) * k + 1;
        int ri = (i)*k;
        int lj = (j - 1) * k + 1;
        int rj = j * k;
        int area = (ri - li + 1) * (rj - lj + 1);
        int sum = d[ri][rj] - d[li - 1][rj] - d[ri][lj - 1] + d[li - 1][lj - 1];
        cur += min(sum, area - sum);
      }
    res = min(res, cur);
  }
  cout << res;
  return 0;
}
