#include <bits/stdc++.h>
const int hsh1 = 1234567, hsh2 = 3214987;
using namespace std;
int n, m;
char puz[25][25];
set<long long> vis;
int cnt = 0, minx = -1, miny = -1;
long long hash1(int x1, int y1, int x2, int y2) {
  long long hs = 0;
  for (int i = x1; i < x2; i++) {
    for (int j = y1; j < y2; j++) hs = hs * hsh1 + puz[i][j];
    hs *= hsh2;
  }
  return hs;
}
long long hash2(int x1, int y1, int x2, int y2) {
  long long hs = 0;
  for (int i = y1; i < y2; i++) {
    for (int j = x2 - 1; j >= x1; j--) hs = hs * hsh1 + puz[j][i];
    hs *= hsh2;
  }
  return hs;
}
long long hash3(int x1, int y1, int x2, int y2) {
  long long hs = 0;
  for (int i = x2 - 1; i >= x1; i--) {
    for (int j = y2 - 1; j >= y1; j--) hs = hs * hsh1 + puz[i][j];
    hs *= hsh2;
  }
  return hs;
}
long long hash4(int x1, int y1, int x2, int y2) {
  long long hs = 0;
  for (int i = y2 - 1; i >= y1; i--) {
    for (int j = x1; j < x2; j++) hs = hs * hsh1 + puz[j][i];
    hs *= hsh2;
  }
  return hs;
}
bool have(long long x) {
  if (vis.count(x))
    return true;
  else
    return false;
}
bool chong(int x1, int x2, int y1, int y2) {
  if (have(hash1(x1, x2, y1, y2))) return true;
  if (have(hash2(x1, x2, y1, y2))) return true;
  if (have(hash3(x1, x2, y1, y2))) return true;
  if (have(hash4(x1, x2, y1, y2))) return true;
  vis.insert(hash1(x1, x2, y1, y2));
  vis.insert(hash2(x1, x2, y1, y2));
  vis.insert(hash3(x1, x2, y1, y2));
  vis.insert(hash4(x1, x2, y1, y2));
  return false;
}
bool cando(int x, int y) {
  if ((n % x) || (m % y)) return false;
  vis.clear();
  for (int i = 0; i * x < n; i++)
    for (int j = 0; j * y < m; j++)
      if (chong(i * x, j * y, (i + 1) * x, (j + 1) * y)) return false;
  return true;
}
int main() {
  scanf("%d%d", &n, &m);
  for (int i = 0; i < n; i++) scanf("%s", puz[i]);
  for (int i = 1; i <= n; i++)
    for (int j = 1; j <= m; j++)
      if (cando(i, j)) {
        cnt++;
        if (minx == -1 || i * j < minx * miny) minx = i, miny = j;
      }
  printf("%d\n%d %d\n", cnt, minx, miny);
  return 0;
}
