#include <bits/stdc++.h>
using namespace std;
struct Node {
  int x, y;
  Node(int x = 0, int y = 0) : x(x), y(y) {}
  bool operator<(const Node& b) const {
    if ((x * y) != (b.x * b.y)) return (x * y) < (b.x * b.y);
    return x < b.x;
  }
};
int n, m;
char s[405][405], a[405][405];
Node ans[405];
bool ss(int p, int q, int w, int h) {
  for (int i = 0; i < w; ++i)
    for (int j = 0; j < h; ++j)
      if (s[p + i][q + j] != a[i][j]) return 0;
  return 1;
}
bool same(int x, int y, int p, int q, int w, int h) {
  for (int i = 0; i < w; ++i)
    for (int j = 0; j < h; ++j) a[i][j] = s[x + i][y + j];
  if (ss(p, q, w, h)) return 1;
  for (int i = 0; i < w; ++i)
    for (int j = 0; j < h; ++j) a[i][j] = s[x + w - 1 - i][y + h - 1 - j];
  if (ss(p, q, w, h)) return 1;
  if (w != h) return 0;
  for (int i = 0; i < w; ++i)
    for (int j = 0; j < h; ++j) a[i][j] = s[x + w - 1 - j][y + i];
  if (ss(p, q, w, h)) return 1;
  for (int i = 0; i < w; ++i)
    for (int j = 0; j < h; ++j) a[i][j] = s[x + j][y + h - 1 - i];
  if (ss(p, q, w, h)) return 1;
  return 0;
}
bool check(int w, int h) {
  for (int i = 0; i < n; i += w)
    for (int j = 0; j < m; j += h)
      for (int p = 0; p < n; p += w)
        for (int q = 0; q < m; q += h)
          if (!(i == p && j == q) && same(i, j, p, q, w, h)) return 0;
  return 1;
}
int main() {
  scanf("%d %d", &n, &m);
  for (int i = 0; i < n; ++i) scanf("%s", s[i]);
  int an = 0;
  for (int i = 1; i <= n; ++i)
    if (n % i == 0)
      for (int j = 1; j <= m; ++j)
        if (m % j == 0)
          if (check(i, j)) ans[an++] = Node(i, j);
  sort(ans, ans + an);
  printf("%d\n", an);
  printf("%d %d\n", ans[0].x, ans[0].y);
  return 0;
}
