#include <bits/stdc++.h>
using namespace std;
const int inf = 0x3f3f3f3f;
int a, b, t, mj = inf, ansx = inf, ansy, q;
string p[405 * 10];
char s[23][23];
void check(int x, int y) {
  t = 0;
  for (int i = 1; i <= 4000; i++) p[i] = "";
  int gx = a / x, gy = b / y;
  for (int i = (1); i <= (gx); i++) {
    for (int j = (1); j <= (gy); j++) {
      int Lx = (i - 1) * x + 1, Rx = i * x;
      int Ly = (j - 1) * y + 1, Ry = j * y;
      t++;
      for (int st = (Lx); st <= (Rx); st++) {
        for (int ed = (Ly); ed <= (Ry); ed++) {
          p[t] += s[st][ed];
        }
      }
      t++;
      for (int st = (Rx); st >= (Lx); st--) {
        for (int ed = (Ry); ed >= (Ly); ed--) {
          p[t] += s[st][ed];
        }
      }
      if (x == y) {
        t++;
        for (int ed = (Ry); ed >= (Ly); ed--) {
          for (int st = (Lx); st <= (Rx); st++) {
            p[t] += s[st][ed];
          }
        }
        t++;
        for (int ed = (Ly); ed <= (Ry); ed++) {
          for (int st = (Rx); st >= (Lx); st--) {
            p[t] += s[st][ed];
          }
        }
      }
    }
  }
  int f = 0;
  if (x != y) {
    for (int i = (1); i <= (t); i++) {
      for (int j = (1); j <= (t); j++) {
        if (p[i] == p[j] && ((i - 1) / 2) != ((j - 1) / 2)) {
          f++;
          break;
        }
      }
    }
  } else {
    for (int i = (1); i <= (t); i++) {
      for (int j = (1); j <= (t); j++) {
        if (p[i] == p[j] && ((i - 1) / 4) != ((j - 1) / 4)) {
          f++;
          break;
        }
      }
    }
  }
  if (!f) {
    q++;
    if (x * y < mj)
      mj = x * y, ansx = x, ansy = y;
    else if (x * y == mj) {
      if (x < ansx) {
        ansx = x, ansy = y;
      }
    }
  }
}
int main() {
  cin >> a >> b;
  for (int i = 1; i <= a; i++)
    for (int j = 1; j <= b; j++) cin >> s[i][j];
  for (int i = (1); i <= (a); i++) {
    for (int j = (1); j <= (b); j++) {
      if (a % i == 0 && b % j == 0) {
        check(i, j);
      }
    }
  }
  if (q) cout << q << endl << ansx << " " << ansy;
  return 0;
}
