#include <bits/stdc++.h>
using namespace std;
vector<vector<char> > rotatee(vector<vector<char> > v) {
  vector<vector<char> > v2(v[0].size(), vector<char>(v.size()));
  for (int i = 0; i < v2.size(); i++) {
    for (int j = 0; j < v2[i].size(); j++) {
      v2[i][j] = v[v.size() - j - 1][i];
    }
  }
  return v2;
}
void print(vector<vector<char> > v) {
  for (int i = 0; i < v.size(); i++) {
    for (int j = 0; j < v[i].size(); j++) {
      cout << v[i][j];
    }
    cout << endl;
  }
}
int main() {
  int a, b;
  cin >> a >> b;
  vector<vector<char> > v(a, vector<char>(b));
  for (int i = 0; i < a; i++) {
    for (int j = 0; j < b; j++) {
      cin >> v[i][j];
    }
  }
  vector<pair<int, pair<int, int> > > result;
  for (int i = 1; i <= a; i++) {
    for (int j = 1; j <= b; j++) {
      bool check = 0;
      if (a % i == 0 && b % j == 0) {
        map<vector<vector<char> >, bool> mop;
        for (int k = 0; k < a; k += i) {
          for (int k1 = 0; k1 < b; k1 += j) {
            vector<vector<char> > v2;
            for (int z = k; z < k + i; z++) {
              vector<char> s;
              for (int z1 = k1; z1 < k1 + j; z1++) {
                s.push_back(v[z][z1]);
              }
              v2.push_back(s);
            }
            if (mop[v2] == 0) {
              mop[v2] = 1;
              v2 = rotatee(v2);
              mop[v2] = 1;
              v2 = rotatee(v2);
              mop[v2] = 1;
              v2 = rotatee(v2);
              mop[v2] = 1;
            } else {
              check = 1;
              break;
            }
          }
          if (check) {
            break;
          }
        }
        if (!check) {
          result.push_back({i * j, {i, j}});
        }
      }
    }
  }
  cout << result.size() << endl;
  sort(result.begin(), result.end());
  cout << result[0].second.first << " " << result[0].second.second;
  return 0;
}
