#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vl = vector<ll>;
using vvl = vector<vl>;
int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  int INF = 1000000000;
  int h, w;
  cin >> h >> w;
  vector<string> g(h);
  for (int i = 0; i < (int)(h); i++) cin >> g[i];
  int ans = 0;
  for (int sy = 0; sy < (int)(h); sy++)
    for (int sx = 0; sx < (int)(w); sx++) {
      if (g[sy][sx] == '#') continue;
      vvi dp(h, vi(w, INF));
      queue<pair<int, int>> q;
      q.push({sy, sx});
      vi v = {1, 0, -1, 0, 1};
      dp[sy][sx] = 0;
      while (!q.empty()) {
        int y = q.front().first;
        int x = q.front().second;
        q.pop();
        for (int i = 0; i < (int)(4); i++) {
          int ny = y + v[i];
          int nx = x + v[i + 1];
          if (ny >= h || nx >= w || ny < 0 || nx < 0) continue;
          if (g[ny][nx] == '#') continue;
          if (dp[ny][nx] > dp[y][x]) {
            dp[ny][nx] = dp[y][x] + 1;
            q.push({ny, nx});
          }
        }
      }
      for (int i = 0; i < (int)(h); i++)
        for (int j = 0; j < (int)(w); j++) {
          if (dp[i][j] == INF) continue;
          ans = max(ans, dp[i][j]);
        }
    }
  cout << ans << endl;
}
