#include <bits/stdc++.h>
using namespace std;
char s[30][30];
int n, m;
int main() {
  scanf("%d%d\n", &n, &m);
  for (int i = 0; i < (n); i++) gets(s[i]);
  int mx = 2147483647, my = 1, k = 0;
  for (int a = (1); a < (n + 1); a++)
    for (int b = (1); b < (m + 1); b++)
      if (n % a == 0 && m % b == 0) {
        bool ok = true;
        for (int q = 0; q <= n - a && ok; q += a)
          for (int w = 0; w <= m - b && ok; w += b)
            for (int e = q; e < n && ok; e += a)
              for (int r = e == q ? w + b : 0; r < m && ok; r += b) {
                bool cok = false;
                for (int i = 0; i < a && ok; i++)
                  for (int j = 0; j < (b); j++)
                    if (s[q + i][w + j] != s[e + i][r + j]) {
                      cok = true;
                      break;
                    }
                if (!cok) ok = false;
              }
        if (a == b && a + b != 2) {
          for (int q = 0; q <= n - a && ok; q += a)
            for (int w = 0; w <= m - b && ok; w += b)
              for (int e = 0; e < n && ok; e += a)
                for (int r = 0; r < m && ok; r += b) {
                  bool cok = false;
                  for (int i = 0, i2 = 0, j2 = a - 1; i < a && ok; i++)
                    for (int j = 0; j < (b); j++) {
                      if (s[q + i][w + j] != s[e + i2][r + j2]) {
                        cok = true;
                        break;
                      }
                      if (i2 == b - 1)
                        i2 = 0, j2--;
                      else
                        i2++;
                    }
                  if (!cok) ok = false;
                }
        }
        for (int q = 0; q <= n - a && ok; q += a)
          for (int w = 0; w <= m - b && ok; w += b)
            for (int e = q; e < n && ok; e += a)
              for (int r = e == q ? w + b : 0; r < m && ok; r += b) {
                bool cok = false;
                for (int i = 0; i < a && ok; i++)
                  for (int j = 0; j < (b); j++)
                    if (s[q + a - 1 - i][w + b - 1 - j] != s[e + i][r + j]) {
                      cok = true;
                      break;
                    }
                if (!cok) ok = false;
              }
        if (ok) {
          k++;
          if (mx * my > a * b || (mx * my == a * b && mx > a)) {
            mx = a;
            my = b;
          }
        }
      }
  printf("%d\n%d %d", k, mx, my);
}
