#include <bits/stdc++.h>
using namespace std;
template <class T, class U>
bool chmin(T &a, const U &b) {
  if (a <= b) return false;
  a = b;
  return true;
}
template <class T, class U>
bool chmax(T &a, const U &b) {
  if (a >= b) return false;
  a = b;
  return true;
}
int Main(int H, int W, vector<string> &S) {
  const int INF = 100000000;
  int ans = 0;
  int HW = H * W;
  vector<vector<int> > d(HW, vector<int>(HW, INF));
  for (int i = 0; i < (int)(HW); i++) {
    for (int j = 0; j < (int)(HW); j++) {
      if (i == j)
        d[i][j] = 0;
      else if (abs(i - j) == 1 && (i / W == j / W) && S[i / W][i % W] == '.' &&
               S[j / W][j % W] == '.')
        d[i][j] = 1;
      else if (abs(i - j) == W && S[i / W][i % W] == '.' &&
               S[j / W][j % W] == '.')
        d[i][j] = 1;
    }
  }
  for (int k = 0; k < (int)(HW); k++)
    for (int i = 0; i < (int)(HW); i++)
      for (int j = 0; j < (int)(HW); j++) {
        d[i][j] = min(d[i][j], d[i][k] + d[k][j]);
      }
  for (int i = 0; i < (int)(HW); i++)
    for (int j = 0; j < (int)(HW); j++) chmax(ans, d[i][j]);
  return ans;
}
int main(void) {
  int H, W;
  cin >> H >> W;
  vector<string> S(H);
  for (int i = 0; i < (int)(H); i++) cin >> S[i];
  cout << Main(H, W, S) << endl;
  return 0;
}
