#include <bits/stdc++.h>
using namespace std;
const int N = 100004;
int n, m, c = 0;
char s[24][24];
set<unsigned long long> st, ns;
bool fun(int x, int y) {
  st.clear();
  for (int i = 0; i < n; i += x)
    for (int j = 0; j < m; j += y) {
      ns.clear();
      unsigned long long sum = 0;
      for (int u = 0; u < x; u++) {
        unsigned long long p = 0;
        for (int v = 0; v < y; v++) p = p * 131 + s[i + u][j + v];
        sum = sum * 997 + p;
      }
      ns.insert(sum);
      sum = 0;
      for (int u = x - 1; u >= 0; u--) {
        unsigned long long p = 0;
        for (int v = y - 1; v >= 0; v--) p = p * 131 + s[i + u][j + v];
        sum = sum * 997 + p;
      }
      ns.insert(sum);
      if (x == y) {
        sum = 0;
        for (int v = y - 1; v >= 0; v--) {
          unsigned long long p = 0;
          for (int u = 0; u < x; u++) p = p * 131 + s[i + u][j + v];
          sum = sum * 997 + p;
        }
        ns.insert(sum);
        sum = 0;
        for (int v = 0; v < y; v++) {
          unsigned long long p = 0;
          for (int u = x - 1; u >= 0; u--) p = p * 131 + s[i + u][j + v];
          sum = sum * 997 + p;
        }
        ns.insert(sum);
      }
      for (auto it = ns.begin(); it != ns.end(); it++) {
        if (st.count(*it)) return 0;
        st.insert(*it);
      }
    }
  return 1;
}
int main() {
  scanf("%d %d", &n, &m);
  for (int i = 0; i < n; i++) scanf("%s", s[i]);
  int x = 100, y = 100, ans = 40000;
  for (int i = 1; i <= n; i++)
    if (n % i == 0)
      for (int j = 1; j <= m; j++)
        if (m % j == 0) {
          if (fun(i, j)) {
            ++c;
            if (i * j < ans || i * j == ans && i < x) {
              ans = i * j;
              x = i;
              y = j;
            }
          }
        }
  printf("%d\n%d %d\n", c, x, y);
}
