#include <bits/stdc++.h>
using namespace std;
int dx[] = {1, 0, -1, 0};
int dy[] = {0, 1, 0, -1};
constexpr int INF = 1e9;
int main() {
  int h, w;
  cin >> h >> w;
  vector<string> s(h);
  for (int i = 0; i < (h); i++) cin >> s[i];
  auto bfs = [&](int sx, int sy) {
    vector<int> d(h * w, INF);
    queue<pair<int, int> > que;
    que.push(make_pair(sx, sy));
    d[sx * w + sy] = 0;
    int mx = 0;
    while (!que.empty()) {
      auto u = que.front();
      que.pop();
      for (int i = 0; i < (4); i++) {
        int x = dx[i] + u.first, y = dy[i] + u.second;
        if (x < 0 || y < 0 || x >= h || y >= w) continue;
        if (s[x][y] == '#') continue;
        if (d[x * w + y] != INF) continue;
        d[x * w + y] = d[u.first * w + u.second] + 1;
        mx = max(mx, d[x * w + y]);
        que.push(make_pair(x, y));
      }
    }
    return mx;
  };
  int res = 0;
  for (int i = 0; i < h; i++) {
    for (int j = 0; j < w; j++) {
      res = max(res, bfs(i, j));
    }
  }
  cout << res << endl;
  return 0;
}
