#include <bits/stdc++.h>
using namespace std;
string S[23];
int n, m, cnt, cx = 24, cy = 24;
bool r1(int x1, int y1, int x2, int y2, int xx, int yy) {
  for (int i = 0; i < xx; i++)
    for (int j = 0; j < yy; j++)
      if (S[x1 + i][y1 + j] != S[x2 + i][y2 + j]) return false;
  return true;
}
bool r2(int x1, int y1, int x2, int y2, int xx, int yy) {
  for (int i = 0; i < xx; i++)
    for (int j = 0; j < yy; j++)
      if (S[x1 + i][y1 + j] != S[x2 + xx - i - 1][y2 + yy - j - 1])
        return false;
  return true;
}
bool r3(int x1, int y1, int x2, int y2, int xx, int yy) {
  for (int i = 0; i < xx; i++)
    for (int j = 0; j < yy; j++)
      if (S[x1 + i][y1 + j] != S[x2 + j][y2 + yy - i - 1]) return false;
  return true;
}
bool r4(int x1, int y1, int x2, int y2, int xx, int yy) {
  for (int i = 0; i < xx; i++)
    for (int j = 0; j < yy; j++)
      if (S[x1 + i][y1 + j] != S[x2 + xx - j - 1][y2 + i]) return false;
  return true;
}
void work(int x, int y) {
  for (int i = 0; i < n; i += x)
    for (int j = 0; j < m; j += y)
      for (int ii = 0; ii < n; ii += x)
        for (int jj = 0; jj < m; jj += y) {
          if (i == ii && j == jj) continue;
          if (r1(i, j, ii, jj, x, y)) return;
          if (r2(i, j, ii, jj, x, y)) return;
          if (x == y) {
            if (r3(i, j, ii, jj, x, y)) return;
            if (r4(i, j, ii, jj, x, y)) return;
          }
        }
  cnt++;
  if (x * y < cx * cy) cx = x, cy = y;
}
int main() {
  cin >> n >> m;
  for (int i = 0; i < n; i++) cin >> S[i];
  for (int i = 1; i <= n; i++)
    if (n % i == 0)
      for (int j = 1; j <= m; j++)
        if (m % j == 0) work(i, j);
  cout << cnt << endl << cx << " " << cy;
  return 0;
}
