#include <bits/stdc++.h>
int main() {
  int A, B;
  std::cin >> A >> B;
  std::vector<std::string> P(A);
  for (int i = 0; i < A; ++i) {
    std::cin >> P[i];
  }
  std::vector<int> X, Y;
  for (int i = 1, eoi = sqrt(A); i <= eoi; ++i) {
    if (A % i == 0) {
      Y.push_back(i);
      Y.push_back(A / i);
    }
  }
  for (int i = 1, eoi = sqrt(B); i <= eoi; ++i) {
    if (B % i == 0) {
      X.push_back(i);
      X.push_back(B / i);
    }
  }
  std::set<std::pair<int, int> > u;
  int res = 0;
  int best = 999999;
  std::pair<int, int> minxy(999, 999);
  for (int i = 0; i < (int)Y.size(); ++i) {
    for (int j = 0; j < (int)X.size(); ++j) {
      int y = Y[i];
      int x = X[j];
      if (u.count(std::make_pair(y, x)) == 1) {
        continue;
      }
      u.insert(std::make_pair(y, x));
      bool ok = true;
      std::set<std::vector<std::string> > used;
      for (int k = 0; k < A && ok; k += y) {
        for (int s = 0; s < B && ok; s += x) {
          std::vector<std::string> p;
          for (int l = k; l < k + y; ++l) {
            p.push_back(P[l].substr(s, x));
          }
          for (int m = 0; m < 2; ++m) {
            for (int l = 0; l < 2; ++l) {
              if (used.count(p)) {
                ok = false;
                break;
              }
              std::reverse(p.begin(), p.end());
              for (int ii = 0; ii < y; ++ii) {
                std::reverse(p[ii].begin(), p[ii].end());
              }
            }
            if (x == y) {
              std::vector<std::string> p2(p);
              for (int ii = 0; ii < y; ++ii) {
                for (int jj = 0; jj < x; ++jj) {
                  p2[ii][jj] = p[jj][y - ii - 1];
                }
              }
              p = p2;
            } else {
              break;
            }
          }
          if (ok) {
            used.insert(p);
          }
        }
      }
      if (ok) {
        ++res;
        if (best > x * y) {
          best = x * y;
          minxy = std::make_pair(y, x);
        } else if (best == x * y) {
          if (y < minxy.first) {
            minxy = std::make_pair(y, x);
          }
        }
      }
    }
  }
  std::cout << res << std::endl;
  std::cout << minxy.first << " " << minxy.second << std::endl;
}
