#include <bits/stdc++.h>
using namespace std;
constexpr double EPS = 1e-9;
constexpr int INF = 1001001001;
constexpr int mod = 1000000007;
constexpr int dx[4] = {1, 0, -1, 0};
constexpr int dy[4] = {0, 1, 0, -1};
int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  int h, w;
  cin >> h >> w;
  vector<string> s(h);
  for (int i = 0; i < h; ++i) cin >> s[i];
  int ans = 0;
  for (int sx = 0; sx < h; ++sx) {
    for (int sy = 0; sy < w; ++sy) {
      if (s[sx][sy] == '#') continue;
      vector<vector<int>> dist(h, vector<int>(w, INF));
      queue<pair<int, int>> que;
      dist[sx][sy] = 0;
      que.push(pair<int, int>(sx, sy));
      while (!que.empty()) {
        pair<int, int> p = que.front();
        que.pop();
        int x = p.first, y = p.second;
        for (int i = 0; i < 4; ++i) {
          int nx = x + dx[i], ny = y + dy[i];
          if (nx < 0 || nx >= h || ny < 0 || ny >= w) continue;
          if (s[nx][ny] == '#') continue;
          if (dist[nx][ny] > dist[x][y] + 1) {
            dist[nx][ny] = dist[x][y] + 1;
            que.push(pair<int, int>(nx, ny));
          }
        }
      }
      for (int gx = 0; gx < h; ++gx) {
        if (gx == sx) continue;
        for (int gy = 0; gy < w; ++gy) {
          if (gy == sy) continue;
          if (s[gx][gy] == '#') continue;
          if (dist[gx][gy] != INF) ans = max(ans, dist[gx][gy]);
        }
      }
    }
  }
  cout << ans << endl;
}
