#include <bits/stdc++.h>
using namespace std;
using i64 = long long;
using P = pair<i64, i64>;
int main() {
  i64 h, w;
  cin >> h >> w;
  vector<string> s(h);
  for (i64 i = 0LL; i < (h); ++i) cin >> s[i];
  vector<i64> dx = {0, 0, 1, -1};
  vector<i64> dy = {1, -1, 0, 0};
  i64 ans = 0;
  for (i64 sx = 0LL; sx < (h); ++sx) {
    for (i64 sy = 0LL; sy < (w); ++sy) {
      vector<vector<i64>> dist(h, vector<i64>(w, -1));
      dist[sx][sy] = 0;
      queue<P> que;
      que.push(P(sx, sy));
      while (!que.empty()) {
        P t = que.front();
        que.pop();
        for (i64 k = 0LL; k < (4); ++k) {
          i64 nx = t.first + dx[k];
          i64 ny = t.second + dy[k];
          if (nx < 0 | nx >= h | ny < 0 | ny >= w) continue;
          if (dist[nx][ny] == -1 && s[nx][ny] == '.') {
            dist[nx][ny] = dist[t.first][t.second] + 1;
            ans = max(ans, dist[nx][ny]);
            que.push(P(nx, ny));
          }
        }
      }
    }
  }
  cout << ans << endl;
}
