#include <bits/stdc++.h>
using namespace std;
int mat[5001][5001];
int psum[5001][5001];
int sum(int fi, int li, int fj, int lj) {
  int big = psum[li][lj];
  int smol = (fi and fj ? psum[fi - 1][fj - 1] : 0);
  int lat1 = (fj ? psum[li][fj - 1] : 0);
  int lat2 = (fi ? psum[fi - 1][lj] : 0);
  return big + smol - lat1 - lat2;
}
int main(int argc, char const *argv[]) {
  ios::sync_with_stdio(0);
  cin.tie(0);
  int n, m;
  cin >> n >> m;
  for (int i = 0; i < 5001; ++i) {
    for (int j = 0; j < 5001; ++j) {
      mat[i][j] = 0;
    }
  }
  for (int i = 0; i < n; ++i) {
    string s;
    cin >> s;
    for (int j = 0; j < m; ++j) {
      mat[i][j] = s[j] - '0';
    }
  }
  psum[0][0] = mat[0][0];
  for (int i = 1; i < 5001; ++i) {
    psum[0][i] = psum[0][i - 1] + mat[0][i];
  }
  for (int i = 1; i < 5001; ++i) {
    psum[i][0] = psum[i - 1][0] + mat[i][0];
  }
  for (int i = 1; i < 5001; ++i) {
    for (int j = 1; j < 5001; ++j) {
      psum[i][j] =
          psum[i][j - 1] + psum[i - 1][j] - psum[i - 1][j - 1] + mat[i][j];
    }
  }
  int ans = 1e9;
  for (int k = 2; k <= 2500; ++k) {
    ;
    int pans = 0;
    for (int i = 0; i < (n + k - 1) / k; ++i) {
      for (int j = 0; j < (m + k - 1) / k; ++j) {
        int c1 = sum(i * k, (i + 1) * k - 1, j * k, (j + 1) * k - 1);
        int c0 = k * k - c1;
        ;
        ;
        ;
        ;
        pans += min(c0, c1);
      }
    };
    ans = min(ans, pans);
  }
  cout << ans << '\n';
  return 0;
}
