#include <bits/stdc++.h>
char d[2600 * 2600];
int calc(char d[], int n, int x, int y, int width) {
  int cnt = 0;
  for (int i = x; i < x + width; i++) {
    for (int j = y; j < y + width; j++) {
      if (d[i * n + j] == 1) cnt++;
    }
  }
  return cnt;
}
int main() {
  int n, m;
  scanf("%d %d", &n, &m);
  char s[2600 + 1];
  for (int i = 0; i < n; i++) {
    scanf("%s", s);
    for (int j = 0; j < m; j++) d[i * 2600 + j] = s[j] - '0';
  }
  int minSum = 100000000;
  for (int i = 2; i <= 20; i++) {
    int sum = 0;
    for (int j = 0; j < n; j += i) {
      for (int k = 0; k < m; k += i) {
        int cnt = calc(d, 2600, j, k, i);
        sum += ((cnt) > (i * i - cnt) ? (i * i - cnt) : (cnt));
      }
    }
    minSum = ((minSum) > (sum) ? (sum) : (minSum));
  }
  printf("%d\n", minSum);
}
