#include <bits/stdc++.h>
using namespace std;
using P = pair<long long, long long>;
using T = tuple<long long, long long, long long>;
vector<long long> dx = {0, -1, 1, 0};
vector<long long> dy = {-1, 0, 0, 1};
signed main() {
  long long h, w;
  cin >> h >> w;
  vector<string> S(h);
  for (long long i = 0; i < h; i++) cin >> S[i];
  long long ans = 0;
  for (long long i = 0; i < h; i++)
    for (long long j = 0; j < w; j++) {
      if (S[i][j] == '.') {
        vector<vector<bool> > judge(h, vector<bool>(w, false));
        long long tmp = 0;
        queue<T> que;
        que.push(make_tuple(i, j, 0));
        while (que.size() > 0) {
          T use = que.front();
          judge[get<0>(use)][get<1>(use)] = true;
          que.pop();
          tmp = max(tmp, get<2>(use));
          for (long long s = 0; s < 4; s++) {
            long long nx = get<0>(use) + dx[s];
            long long ny = get<1>(use) + dy[s];
            if (0 <= nx && nx < h && 0 <= ny && ny < w) {
              if (S[nx][ny] == '.' && !(judge[nx][ny]))
                que.push(make_tuple(nx, ny, get<2>(use) + 1));
            }
          }
        }
        ans = max(ans, tmp);
      }
    }
  cout << ans << endl;
}
