#include <bits/stdc++.h>
using namespace std;
char mat[22][22];
vector<string> rot90(vector<string> s) {
  vector<string> ret(s[0].size(), string(s.size(), ' '));
  for (int i = 0; i < s.size(); ++i) {
    for (int j = 0; j < s[0].size(); ++j) {
      ret[((int)s[0].size()) - j - 1][i] = s[i][j];
    }
  }
  return ret;
}
vector<vector<string> > allRot(vector<string> ss) {
  vector<vector<string> > res;
  res.push_back(ss);
  for (int i = 0; i < 3; ++i) {
    ss = rot90(ss);
    res.push_back(ss);
  }
  sort(res.begin(), res.end());
  return res;
}
int main() {
  int A, B;
  cin >> A >> B;
  for (int i = 0; i < A; ++i) {
    for (int j = 0; j < B; ++j) {
      cin >> mat[i][j];
    }
  }
  int cnt = 0;
  int mxA = 1e9;
  int bx, by;
  for (int x = 1; x <= A; ++x) {
    if (A % x) continue;
    for (int y = 1; y <= B; ++y) {
      if (B % y) continue;
      set<vector<vector<string> > > allP;
      for (int i = 0; i < A; i += x) {
        for (int j = 0; j < B; j += y) {
          vector<string> ss;
          for (int ii = i; ii < i + x; ++ii) {
            string s = "";
            for (int jj = j; jj < j + y; ++jj) {
              s += mat[ii][jj];
            }
            ss.push_back(s);
          }
          for (int l = 0; l < ss.size(); ++l) {
          }
          vector<vector<string> > temp = allRot(ss);
          for (int k = 0; k < temp.size(); ++k) {
            for (int l = 0; l < temp[k].size(); ++l) {
            }
          }
          allP.insert(allRot(ss));
        }
      }
      if (allP.size() == ((A / x) * (B / y))) {
        cnt++;
        if (x * y < mxA || (x * y == mxA && x < bx)) {
          bx = x;
          by = y;
          mxA = x * y;
        }
      }
    }
  }
  cout << cnt << endl;
  cout << bx << " " << by << endl;
  return 0;
}
