#include <bits/stdc++.h>
using namespace std;
const int MAXN = 25;
char mp[MAXN][MAXN];
set<string> s;
int n, m;
bool InSet(int x0, int y0, int x1, int y1) {
  string st;
  if (y1 - y0 == x1 - x0) {
    st = "";
    for (int i = x0; i <= x1; i++)
      for (int j = y0; j <= y1; j++) st += mp[i][j];
    if (s.count(st) > 0) return true;
    st = "";
    for (int i = x1; i >= x0; i--)
      for (int j = y1; j >= y0; j--) st += mp[i][j];
    if (s.count(st) > 0) return true;
  }
  st = "";
  for (int j = y1; j >= y0; j--)
    for (int i = x0; i <= x1; i++) st += mp[i][j];
  if (s.count(st) > 0) return true;
  st = "";
  for (int j = y0; j <= y1; j++)
    for (int i = x1; i >= x0; i--) st += mp[i][j];
  if (s.count(st) > 0) return true;
  s.insert(st);
  return false;
}
bool CheckPairSize(int a, int b) {
  s.clear();
  for (int a0 = 0; a0 < n; a0 += a)
    for (int b0 = 0; b0 < m; b0 += b)
      if (InSet(a0, b0, a0 + a - 1, b0 + b - 1)) return false;
  return true;
}
int main() {
  int ans = 0, ansX, ansY;
  scanf("%d%d", &n, &m);
  for (int i = 0; i < n; i++) scanf("%s", mp[i]);
  for (int a = 1; a <= n; a++)
    for (int b = 1; b <= m; b++)
      if (n % a == 0 && m % b == 0 && CheckPairSize(a, b)) {
        if (ans == 0 || ansX * ansY > a * b || ansX * ansY == a * b && ansX > a)
          ansX = a, ansY = b;
        ans++;
      }
  printf("%d\n%d %d\n", ans, ansX, ansY);
  return 0;
}
