#include <bits/stdc++.h>
using namespace std;
const long long mod = 1e9 + 7;
long long dx[] = {1, -1, 0, 0, 1, -1, 1, -1};
long long dy[] = {0, 0, 1, -1, 1, -1, -1, 1};
long long n, m, res;
string s[25];
set<vector<string>> st;
vector<string> rotate(vector<string>& v) {
  long long a = v.size(), b = v[0].size();
  vector<string> res;
  for (long long i = 0; i < b; i++) {
    string str = "";
    for (long long j = a - 1; j >= 0; j--) str += v[j][i];
    res.push_back(str);
  }
  return res;
}
bool fun(long long a, long long b) {
  st.clear();
  for (long long i = 0; i < n; i += a)
    for (long long j = 0; j < m; j += b) {
      vector<string> aux;
      for (long long x = i; x < i + a; x++) {
        string str = "";
        for (long long y = j; y < j + b; y++) str += s[x][y];
        aux.push_back(str);
      }
      if (st.find(aux) != st.end()) return 0;
      st.insert(aux);
      aux = rotate(aux);
      st.insert(aux);
      aux = rotate(aux);
      st.insert(aux);
      aux = rotate(aux);
      st.insert(aux);
    }
  return 1;
}
int32_t main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  cin >> n >> m;
  bool first = true;
  long long rx = 21, ry = 21;
  for (long long i = 0; i < n; i++) cin >> s[i];
  for (long long i = 1; i <= n; i++) {
    if (n % i == 0)
      for (long long j = 1; j <= m; j++) {
        if (m % j == 0)
          if (fun(i, j)) {
            res++;
            if (i * j < rx * ry || (i * j == rx * ry && i < rx)) {
              rx = i;
              ry = j;
            }
          }
      }
  }
  cout << res << "\n";
  cout << rx << " " << ry << "\n";
}
