#include <bits/stdc++.h>
using namespace std;
char str[30][30];
char tmp[500];
string c[1600];
int main() {
  int n, m, x, y, i, j, k, h, r, p, q, total, dx, dy;
  while (scanf("%d %d", &n, &m) == 2) {
    for (i = 0; i < n; i++) {
      scanf("%s", str[i]);
    }
    dx = 1000;
    dy = 1000;
    total = 0;
    for (x = 1; x <= n; x++) {
      for (y = 1; y <= m; y++) {
        if (n % x || m % y) continue;
        r = 0;
        for (i = 0; i < n; i += x) {
          for (j = 0; j < m; j += y) {
            p = 0;
            q = r;
            for (k = 0; k < x; k++) {
              for (h = 0; h < y; h++) {
                tmp[p++] = str[i + k][j + h];
              }
            }
            tmp[p] = 0;
            c[r] = tmp;
            for (k = q; k < r; k++) {
              if (c[r] == c[k]) break;
            }
            if (k == r) r++;
            p = 0;
            for (k = x - 1; k >= 0; k--) {
              for (h = y - 1; h >= 0; h--) {
                tmp[p++] = str[i + k][j + h];
              }
            }
            tmp[p] = 0;
            c[r] = tmp;
            for (k = q; k < r; k++) {
              if (c[r] == c[k]) break;
            }
            if (k == r) r++;
            if (x == y) {
              p = 0;
              for (k = y - 1; k >= 0; k--) {
                for (h = 0; h < x; h++) {
                  tmp[p++] = str[i + h][j + k];
                }
              }
              tmp[p] = 0;
              c[r] = tmp;
              for (k = q; k < r; k++) {
                if (c[r] == c[k]) break;
              }
              if (k == r) r++;
              p = 0;
              for (k = 0; k < y; k++) {
                for (h = x - 1; h >= 0; h--) {
                  tmp[p++] = str[i + h][j + k];
                }
              }
              tmp[p] = 0;
              c[r] = tmp;
              for (k = q; k < r; k++) {
                if (c[r] == c[k]) break;
              }
              if (k == r) r++;
            }
          }
        }
        sort(c, c + r);
        for (i = 1; i < r; i++) {
          if (c[i] == c[i - 1]) break;
        }
        if (i == r) {
          total++;
          if (x * y < dx * dy) {
            dx = x;
            dy = y;
          } else if (x * y == dx * dy && x < dx) {
            dx = x;
            dy = y;
          }
        }
      }
    }
    printf("%d\n", total);
    printf("%d %d\n", dx, dy);
  }
  return 0;
}
