#include <bits/stdc++.h>
using namespace std;
struct Puzzle {
  int x, y;
  Puzzle() {}
  Puzzle(int x, int y) : x(x), y(y) {}
  bool operator<(const Puzzle &o) const {
    if (x * y == o.x * o.y) {
      return x < o.x;
    }
    return x * y < o.x * o.y;
  }
};
void rotate(vector<vector<char> > &x) {
  vector<vector<char> > ret(((int)x[0].size()), vector<char>(((int)x.size())));
  for (int i = 0; i < ((int)x.size()); ++i)
    for (int j = 0; j < ((int)x[0].size()); ++j) {
      ret[j][((int)x.size()) - i - 1] = x[i][j];
    }
  x = ret;
}
void solve() {
  int a, b;
  cin >> a >> b;
  vector<vector<char> > table;
  for (int i = 0; i < a; ++i) {
    string s;
    cin >> s;
    table.push_back(vector<char>(s.begin(), s.end()));
  }
  Puzzle mn(a, b);
  int ans = 0;
  for (int x = 1; x <= a; ++x)
    for (int y = 1; y <= b; ++y) {
      if (a % x != 0) {
        break;
      }
      if (b % y != 0) {
        continue;
      }
      set<vector<vector<char> > > was;
      bool ok = true;
      for (int i = 0; i < a / x; ++i)
        for (int j = 0; j < b / y; ++j) {
          vector<vector<char> > part(x, vector<char>(y));
          for (int cx = 0; cx < x; ++cx)
            for (int cy = 0; cy < y; ++cy) {
              part[cx][cy] = table[cx + x * i][cy + y * j];
            }
          if (was.count(part) == 0) {
            for (int i = 0; i < 4; ++i) {
              was.insert(part);
              rotate(part);
            }
          } else {
            ok = false;
          }
        }
      if (ok) {
        mn = min(mn, Puzzle(x, y));
        ++ans;
      }
    }
  cout << ans << endl << mn.x << " " << mn.y << endl;
}
int main() {
  ios_base::sync_with_stdio(false);
  solve();
  return 0;
}
