#include <bits/stdc++.h>
using namespace std;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
vector<string> field;
int H, W;
int BFS(int sh, int sw) {
  vector<int> dist(450, -1);
  int max_dist = 0;
  queue<int> que;
  dist[sh * W + sw] = 0;
  que.push(sh * W + sw);
  while (!que.empty()) {
    int v = que.front();
    que.pop();
    int h = v / W;
    int w = v % W;
    cout << h << " " << w << endl;
    for (int dir = 0; dir < 4; dir++) {
      int nh = h + dx[dir];
      int nw = w + dy[dir];
      if (nh < 0 || nh >= H || nw < 0 || nw >= W) continue;
      if (field[nh][nw] == '#') continue;
      if (dist[nh * W + nw] != -1) continue;
      int ndist = dist[v] + 1;
      max_dist = max(ndist, max_dist);
      dist[nh * W + nw] = ndist;
      que.push(nh * W + nw);
    }
  }
  return max_dist;
}
int main() {
  cin >> H >> W;
  field.resize(H);
  for (int i = 0; i < H; i++) cin >> field[i];
  int max_dist = 0;
  for (int h = 0; h < H; h++) {
    for (int w = 0; w < W; w++) {
      if (field[h][w] != '#') max_dist = max(max_dist, BFS(h, w));
    }
  }
  cout << max_dist << endl;
  cout << BFS(0, 0) << endl;
  return 0;
}
