#include <bits/stdc++.h>
using namespace std;
const int inf = 1e9 + 7;
const long long longinf = 1LL << 60;
const long long mod = 1e9 + 7;
int main() {
  int H, W;
  cin >> H;
  cin >> W;
  long long maze[H][W];
  vector<string> S;
  string temp;
  for (int i = (int)(0); i < (int)(H); i++) {
    cin >> temp;
    S.push_back(temp);
  }
  for (int i = (int)(0); i < (int)(H); i++) {
    for (int j = (int)(0); j < (int)(W); j++) {
      if (S[i].substr(j, 1) == ".") {
        maze[i][j] = 0;
      } else {
        maze[i][j] = 1;
      }
    }
  }
  long long d[H * W][H * W];
  for (int s = (int)(0); s < (int)(H * W); s++) {
    for (int e = (int)(0); e < (int)(H * W); e++) {
      if (s == e) {
        d[s][e] = 0;
      } else if ((maze[s / W][s % W] == 0) and (maze[e / W][e % W] == 0) and
                 (((abs((s / W) - (e / W)) == 1) and ((s % W) == (e % W))) or
                  ((abs((s % W) - (e % W)) == 1) and ((s / W) == (e / W))))) {
        d[s][e] = 1;
      } else {
        d[s][e] = inf;
      }
    }
  }
  for (int m = (int)(0); m < (int)(H * W); m++) {
    for (int s = (int)(0); s < (int)(H * W); s++) {
      for (int e = (int)(0); e < (int)(H * W); e++) {
        d[s][e] = min(d[s][e], d[s][m] + d[m][e]);
      }
    }
  }
  long long ans = 0;
  long long ans_s, ans_e;
  for (int s = (int)(0); s < (int)(H * W); s++) {
    for (int e = (int)(0); e < (int)(H * W); e++) {
      if (d[s][e] == inf) continue;
      if (d[s][e] > ans) {
        ans = d[s][e];
        ans_s = s;
        ans_e = e;
      }
    }
  }
  cout << "ans_s: "
       << "(" << ans_s / W << ", " << ans_s % W << ")" << endl;
  cout << "ans_e: "
       << "(" << ans_e / W << ", " << ans_e % W << ")" << endl;
  cout << ans << endl;
  return 0;
}
