#include <bits/stdc++.h>
using namespace std;
const int MAX_N = 22;
const int MAX_M = 22;
const long long BASE = 10007;
int n, m;
char a[MAX_N][MAX_M];
long long b[MAX_N][MAX_M], c[MAX_N][MAX_M];
map<long long, bool> q;
void to_b(int x1, int y1, int x2, int y2) {
  int x = 0;
  for (int i = int(x1); i <= int(x2); ++i) {
    ++x;
    int y = 0;
    for (int j = int(y1); j <= int(y2); ++j) {
      b[x][++y] = a[i][j];
    }
  }
}
void print_b(int x, int y) {
  cout << "Print B!!!" << endl;
  for (int i = int(1); i <= int(x); ++i) {
    for (int j = int(1); j <= int(y); ++j) cout << b[i][j] << " ";
    cout << endl;
  }
  cout << endl;
}
void rotate_b_90(int x) {
  for (int i = int(1); i <= int(x); ++i) {
    int ii = x + 1;
    for (int j = int(1); j <= int(x); ++j) c[--ii][i] = b[i][j];
  }
  for (int i = int(1); i <= int(x); ++i)
    for (int j = int(1); j <= int(x); ++j) b[i][j] = c[i][j];
}
void rotate_b_180(int x, int y) {
  int ii = x + 1;
  for (int i = int(1); i <= int(x); ++i) {
    --ii;
    int jj = y + 1;
    for (int j = int(1); j <= int(y); ++j) c[ii][--jj] = b[i][j];
  }
  for (int i = int(1); i <= int(x); ++i)
    for (int j = int(1); j <= int(y); ++j) b[i][j] = c[i][j];
}
long long get_h(int x, int y) {
  long long h = 0;
  for (int i = int(1); i <= int(x); ++i)
    for (int j = int(1); j <= int(y); ++j) h = h * BASE + b[i][j];
  return h;
}
bool check(int x, int y) {
  if (n % x || m % y) return false;
  q.clear();
  long long v[5];
  for (int i = 0; i < int(n / x); ++i)
    for (int j = 0; j < int(m / y); ++j) {
      to_b(i * x + 1, j * y + 1, (i + 1) * x, (j + 1) * y);
      if (x == y) {
        for (int k = 0; k < int(4); ++k) {
          rotate_b_90(x);
          v[k] = get_h(x, y);
          if (q.find(v[k]) != q.end()) return false;
        }
        for (int k = 0; k < int(4); ++k) q[v[k]] = true;
      } else {
        for (int k = 0; k < int(2); ++k) {
          rotate_b_180(x, y);
          v[k] = get_h(x, y);
          if (q.find(v[k]) != q.end()) return false;
        }
        for (int k = 0; k < int(2); ++k) q[v[k]] = true;
      }
    }
  return true;
}
int main() {
  cin >> n >> m;
  for (int i = int(1); i <= int(n); ++i)
    for (int j = int(1); j <= int(m); ++j) cin >> a[i][j];
  int res = 0, x = n, y = m;
  for (int i = int(1); i <= int(n); ++i) {
    for (int j = int(1); j <= int(m); ++j)
      if (check(i, j)) {
        ++res;
        if (i * j < x * y) {
          x = i;
          y = j;
        }
      }
  }
  printf("%d\n%d %d", res, x, y);
  return 0;
}
