#include <bits/stdc++.h>
using namespace std;
int main() {
  int r, c;
  scanf("%d%d", &r, &c);
  char list[25][25];
  for (int i = 0; i < r; i++) scanf("%s", list[i]);
  int res = INT_MAX, X = INT_MAX, Y = INT_MAX;
  int total = 0;
  for (int i = 1; i <= r; i++) {
    if (r % i == 0) {
      for (int j = 1; j <= c; j++) {
        if (c % j == 0) {
          set<string> s;
          bool can = true;
          for (int p = 0; p < r; p += i) {
            if (!can) break;
            for (int q = 0; q < c; q += j) {
              string tmp1, tmp2, tmp3, tmp4;
              for (int x = p; x < p + i; x++) {
                for (int y = q; y < q + j; y++) {
                  tmp1 += list[x][y];
                }
              }
              for (int x = p + i - 1; x >= p; x--) {
                for (int y = q + j - 1; y >= q; y--) {
                  tmp2 += list[x][y];
                }
              }
              if (i == j) {
                for (int y = q + j - 1; y >= q; y--) {
                  for (int x = p; x < p + i; x++) {
                    tmp3 += list[x][y];
                  }
                }
                for (int y = q; y < q + j; y++) {
                  for (int x = p + i - 1; x >= p; x--) {
                    tmp4 += list[x][y];
                  }
                }
                if (s.find(tmp1) == s.end() && s.find(tmp2) == s.end() &&
                    s.find(tmp3) == s.end() && s.find(tmp4) == s.end()) {
                  s.insert(tmp1);
                  s.insert(tmp2);
                  s.insert(tmp3);
                  s.insert(tmp4);
                } else {
                  can = false;
                  break;
                }
              } else {
                if (s.find(tmp1) == s.end() && s.find(tmp2) == s.end()) {
                  s.insert(tmp1);
                  s.insert(tmp2);
                } else {
                  can = false;
                  break;
                }
              }
            }
          }
          if (can) {
            total++;
            if (i * j < res) {
              res = i * j;
              X = i;
              Y = j;
            } else if (i * j == res && X > i) {
              X = i;
              Y = j;
            }
          }
        }
      }
    }
  }
  printf("%d\n%d %d\n", total, X, Y);
  return 0;
}
