#include <bits/stdc++.h>
using namespace std;
const int def_l[] = {0, 0, -1, 1};
const int def_r[] = {-1, 1, 0, 0};
const int INF = 1001001001;
int main() {
  int h, w;
  cin >> h >> w;
  vector<string> S(h);
  for (int i = 0; i < h; i++) cin >> S[i];
  for (int i = 0; i < h; i++) cout << S[i];
  int ans = 0;
  for (int si = 0; si < h; si++)
    for (int sj = 0; sj < w; sj++) {
      if (S[si][sj] == '#') continue;
      vector<vector<int>> dist(h, vector<int>(w, INF));
      queue<pair<int, int>> q;
      auto update = [&](int i, int j, int x) {
        if (dist[i][j] != INF) return;
        dist[i][j] = x;
        q.push(pair<int, int>(i, j));
      };
      update(si, sj, 0);
      while (!q.empty()) {
        int i = q.front().first;
        int j = q.front().second;
        q.pop();
        for (int ret = 0; ret < 4; ret++) {
          int in = i + def_l[ret], jn = j + def_r[ret];
          if (in < 0 || in >= h || jn < 0 || jn >= w) continue;
          if (S[in][jn] == '#') continue;
          update(in, jn, dist[i][j] + 1);
        }
      }
      for (int i = 0; i < h; i++)
        for (int j = 0; j < w; j++) {
          if (dist[i][j] == INF) continue;
          ans = max(ans, dist[i][j]);
        }
    }
  cout << ans << endl;
}
