#include <bits/stdc++.h>
using namespace std;
int rd() {
  char ch = getchar();
  while (ch < 'A' || ch > 'Z') ch = getchar();
  return (int)ch - 64;
}
int n, m, mp[21][21], u, v;
struct pt {
  int h[21][21];
} f, g;
void prtf(pt as, int op) {
  if (op == 0) printf("\n");
  if (op == 0) printf("Print Map='F'\n");
  if (op == 1) printf("Print Map='G'\n");
  for (int i = 1; i <= u; i++) {
    for (int j = 1; j <= v; j++) printf("%d ", as.h[i][j]);
    printf("\n");
  }
  return;
}
bool equ() {
  bool flg = true;
  for (int i = 1; i <= u; i++)
    for (int j = 1; j <= v; j++)
      if (f.h[i][j] != g.h[i][j]) {
        flg = false;
        break;
      }
  if (flg) return true;
  flg = true;
  for (int i = 1; i <= u; i++)
    for (int j = 1; j <= v; j++)
      if (f.h[u - i + 1][v - j + 1] != g.h[i][j]) {
        flg = false;
        break;
      }
  if (flg) return true;
  if (u != v) return false;
  flg = true;
  for (int i = 1; i <= u; i++)
    for (int j = 1; j <= v; j++)
      if (f.h[j][u - i + 1] != g.h[i][j]) {
        flg = false;
        break;
      }
  if (flg) return true;
  flg = true;
  for (int i = 1; i <= u; i++)
    for (int j = 1; j <= v; j++)
      if (g.h[j][u - i + 1] != f.h[i][j]) {
        flg = false;
        break;
      }
  if (flg) return true;
  return false;
}
bool chck(int x, int y) {
  int tx = n / x, ty = m / y;
  u = x;
  v = y;
  for (int a = 0; a < tx; a++)
    for (int b = 0; b < ty; b++)
      for (int c = 0; c < tx; c++)
        for (int d = 0; d < ty; d++)
          if (a != c || b != d) {
            for (int sx = 1; sx <= x; sx++)
              for (int sy = 1; sy <= y; sy++)
                f.h[sx][sy] = mp[a * x + sx][b * y + sy];
            for (int sx = 1; sx <= x; sx++)
              for (int sy = 1; sy <= y; sy++)
                g.h[sx][sy] = mp[c * x + sx][d * y + sy];
            bool rc = equ();
            if (rc) return false;
          }
  return true;
}
int main() {
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= n; i++)
    for (int j = 1; j <= m; j++) mp[i][j] = rd();
  int tt = 0, tx = n, ty = m;
  for (int x = 1; x <= n; x++)
    for (int y = 1; y <= m; y++)
      if (n % x == 0 && m % y == 0) {
        if (chck(x, y)) {
          tt++;
          if (x * y < tx * ty) {
            tx = x;
            ty = y;
          }
        }
      }
  printf("%d\n%d %d\n", tt, tx, ty);
  return 0;
}
