#include <bits/stdc++.h>
const int64_t kInfty = 1e18;
const double kEps = 1e-7;
const int64_t kMaxN = 2500 + 7;
int64_t n, m;
int64_t a[kMaxN][kMaxN];
int64_t pref[kMaxN][kMaxN];
inline int64_t Get(int64_t x, int64_t y, int64_t u, int64_t v) {
  return pref[u][v] - pref[u][y - 1] - pref[x - 1][v] + pref[x - 1][y - 1];
}
int64_t Toggle(int64_t k) {
  int64_t res = 0;
  for (int64_t i = 1; i <= n; i += k)
    for (int64_t j = 1; j <= m; j += k) {
      int64_t x = Get(i, j, std::min(i + k - 1, n), std::min(j + k - 1, m));
      x = std::min(x, k * k - x);
      res += x;
    }
  return res;
}
int32_t main() {
  std::ios_base::sync_with_stdio(false);
  std::cin.tie(nullptr);
  std::cin >> n >> m;
  for (int64_t i = 1; i <= n; ++i)
    for (int64_t j = 1; j <= m; ++j) {
      char c;
      std::cin >> c;
      a[i][j] = c - '0';
    }
  for (int64_t i = 1; i < kMaxN; ++i)
    for (int64_t j = 1; j < kMaxN; ++j)
      pref[i][j] =
          pref[i - 1][j] + pref[i][j - 1] - pref[i - 1][j - 1] + a[i][j];
  int64_t res = kInfty;
  for (int64_t k = 2; k <= std::max(n, m); ++k) {
    int64_t cost = Toggle(k);
    res = std::min(res, cost);
  }
  std::cout << res;
}

### Prompt

In CPP, your task is to solve the following problem:

You are given an image, that can be represented with a 2-d n by m grid of pixels. Each pixel of the image is either on or off, denoted by the characters "0" or "1", respectively. You would like to compress this image. You want to choose an integer k > 1 and split the image into k by k blocks. If n and m are not divisible by k, the image is padded with only zeros on the right and bottom so that they are divisible by k. Each pixel in each individual block must have the same value. The given image may not be compressible in its current state. Find the minimum number of pixels you need to toggle (after padding) in order for the image to be compressible for some k. More specifically, the steps are to first choose k, then the image is padded with zeros, then, we can toggle the pixels so it is compressible for this k. The image must be compressible in that state.

Input

The first line of input will contain two integers n, m (2 ≤ n, m ≤ 2 500), the dimensions of the image.

The next n lines of input will contain a binary string with exactly m characters, representing the image.

Output

Print a single integer, the minimum number of pixels needed to toggle to make the image compressible.

Example

Input

3 5
00100
10110
11001


Output

5

Note

We first choose k = 2.

The image is padded as follows: 
    
    
      
    001000  
    101100  
    110010  
    000000  
    

We can toggle the image to look as follows: 
    
    
      
    001100  
    001100  
    000000  
    000000  
    

We can see that this image is compressible for k = 2.

### Response

```cpp
#include <bits/stdc++.h>
const int64_t kInfty = 1e18;
const double kEps = 1e-7;
const int64_t kMaxN = 2500 + 7;
int64_t n, m;
int64_t a[kMaxN][kMaxN];
int64_t pref[kMaxN][kMaxN];
inline int64_t Get(int64_t x, int64_t y, int64_t u, int64_t v) {
  return pref[u][v] - pref[u][y - 1] - pref[x - 1][v] + pref[x - 1][y - 1];
}
int64_t Toggle(int64_t k) {
  int64_t res = 0;
  for (int64_t i = 1; i <= n; i += k)
    for (int64_t j = 1; j <= m; j += k) {
      int64_t x = Get(i, j, std::min(i + k - 1, n), std::min(j + k - 1, m));
      x = std::min(x, k * k - x);
      res += x;
    }
  return res;
}
int32_t main() {
  std::ios_base::sync_with_stdio(false);
  std::cin.tie(nullptr);
  std::cin >> n >> m;
  for (int64_t i = 1; i <= n; ++i)
    for (int64_t j = 1; j <= m; ++j) {
      char c;
      std::cin >> c;
      a[i][j] = c - '0';
    }
  for (int64_t i = 1; i < kMaxN; ++i)
    for (int64_t j = 1; j < kMaxN; ++j)
      pref[i][j] =
          pref[i - 1][j] + pref[i][j - 1] - pref[i - 1][j - 1] + a[i][j];
  int64_t res = kInfty;
  for (int64_t k = 2; k <= std::max(n, m); ++k) {
    int64_t cost = Toggle(k);
    res = std::min(res, cost);
  }
  std::cout << res;
}

```