#include <bits/stdc++.h>
using namespace std;
vector<string> rot(vector<string>& a) {
  int n = a.size();
  int m = a[0].size();
  vector<string> res(m, string(n, ' '));
  for (int i = (0); i < ((n)); ++i)
    for (int j = (0); j < ((m)); ++j) res[j][i] = a[i][m - 1 - j];
  return res;
}
int main() {
  int height, width;
  while (cin >> height >> width) {
    vector<pair<int, pair<int, int> > > comp;
    vector<string> v(height);
    for (int i = (0); i < ((height)); ++i) cin >> v[i];
    for (int x = (1); x < (height + 1); ++x)
      for (int y = (1); y < (width + 1); ++y) {
        if (height % x || width % y) continue;
        bool ok = true;
        set<vector<string> > s;
        for (int i = 0; i < height; i += x)
          for (int j = 0; j < width; j += y) {
            vector<string> t(x, string(y, ' '));
            for (int k = (0); k < ((x)); ++k)
              for (int l = (0); l < ((y)); ++l) t[k][l] = v[i + k][j + l];
            if (((s).find(t) != (s).end())) {
              ok = false;
              goto HOGE;
            }
            vector<string> t2 = rot(t);
            if (t.size() == t2.size()) {
              if (((s).find(t2) != (s).end())) {
                ok = false;
                goto HOGE;
              }
            }
            t = rot(t2);
            if (((s).find(t) != (s).end())) {
              ok = false;
              goto HOGE;
            }
            t2 = rot(t);
            if (t.size() == t2.size()) {
              if (((s).find(t2) != (s).end())) {
                ok = false;
                goto HOGE;
              }
            }
            s.insert(t);
          }
      HOGE:
        if (ok || (x == height && y == width)) {
          comp.push_back(make_pair(x * y, make_pair(x, y)));
        }
      }
    sort((comp).begin(), (comp).end());
    cout << comp.size() << endl;
    cout << comp[0].second.first << " " << comp[0].second.second << endl;
  }
  return 0;
}
