#include <bits/stdc++.h>
using namespace std;
int di[] = {1, -1, 0, 0};
int dj[] = {0, 0, 1, -1};
const int INF = 1001001001;
int main() {
  int h, w;
  cin >> h >> w;
  vector<string> g(h);
  for (int i = 0; i < (h); ++i) cin >> g[i];
  vector<vector<int> > dist(h * w, vector<int>(h * w, INF));
  for (int i = 0; i < (h); ++i)
    for (int j = 0; j < (w); ++j) {
      if (g[i][j] == '#') continue;
      for (int k = 0; k < (4); ++k) {
        int dy = i + di[k];
        int dx = j + dj[k];
        if (dy < 0 or dy >= h or dx < 0 or dx >= w) continue;
        if (g[dy][dx] == '#') continue;
        dist[(i * h) + j][(dy * h) + dx] = 1;
      }
    }
  for (int k = 0; k < (h * w); ++k) {
    for (int i = 0; i < (h * w); ++i) {
      for (int j = 0; j < (h * w); ++j) {
        dist[i][j] = min(dist[i][j], dist[i][k] + dist[k][j]);
      }
    }
  }
  int ans = 0;
  for (int i = 0; i < (h * w); ++i) {
    for (int j = 0; j < (h * w); ++j) {
      if (dist[i][j] != INF) ans = max(ans, dist[i][j]);
    }
  }
  cout << ans << endl;
  return 0;
}
