#include <bits/stdc++.h>
using namespace std;
int main() {
  int h, w;
  bool s[400];
  int d[400][400];
  cin >> h >> w;
  for (int i = 0; i < h; i++) {
    for (int j = 0; j < w; j++) {
      char c;
      cin >> c;
      s[i * w + j] = c == '.';
    }
  }
  for (int i = 0; i < h * w; i++) {
    for (int j = 0; j < h * w; j++) {
      if (not s[i] || not s[j]) {
        d[i][j] = 40000;
      } else if (i == j) {
        d[i][j] = 0;
      } else {
        d[i][j] = 40000;
      }
    }
  }
  while (true) {
    bool flag = false;
    for (int p = 0; p < h * w; p++) {
      for (int k = 0; k < h * w; k++) {
        int x = p / w;
        int y = p % w;
        for (int i = max(0, x - 1); i < min(h, x + 2); i++) {
          for (int j = max(0, y - 1); j < min(w, y + 2); j++) {
            if ((x - i) * (y - j) != 0) continue;
            if (not s[i * w + j]) continue;
            if (d[p][k] > d[i * w + j][k] + 1) {
              d[p][k] = d[i * w + j][k] + 1;
              d[k][p] = d[i * w + j][k] + 1;
              flag = true;
            }
          }
        }
      }
    }
    if (not flag) break;
  }
  int m = 0;
  for (int i = 0; i < h * w; i++) {
    for (int j = 0; j < h * w; j++) {
      if (d[i][j] == 40000) continue;
      m = max(d[i][j], m);
    }
  }
  cout << m << endl;
  return 0;
}
