include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
const int inf = 1e9;
const ll mod = 1e9 + 7;
const int dx[] = {1, 0, -1, 0}, dy[] = {0, 1, 0, -1};

int main() {
  int h, w;
  cin >> h >> w;
  vector<string> f(h);
  rep(i,h) cin >> f[i];
  rep(si,h)rep(sj,w) {
    if (f[si][sj] == '#') continue;
    vector<vector<int>> dist(h, vector<int>(w, INF));
    queue<P> q;
    auto update = [&](int i, int j, int x){
      if (dist[i][j] != INF) return;
      dist[i][j] = x;
      q.push(P(i,j));
    };
    update(si,sj,0);
    while (!q.empty()) {
      int i = q.front().first;
      int j = q.front().second;
      rep(dir,4) {
        int ni = i + dx[dir], nj = j + dy[dir];
        if (ni<0||ni>=h||nj<0||nj>=w) continue;
        if (s[ni][nj] == '#') continue;
        update(ni,nj,dist[i][j]+1);
      }
    }
    rep(i,h)rep(i,w) {
      if (dist[i][j] == INF) continue;
      ans = max(ans,dist[i][j]);
    }
  }
  cout << ans << endl;
  return 0;
}
