#include <bits/stdc++.h>
using namespace std;
const int p[] = {-1, 0, 1, 0};
const int v[] = {0, -1, 0, 1};
int main() {
  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 i = 0; i < h; i++)
    for (int j = 0; j < w; j++) {
      if (s[i][j] == '#') continue;
      vector<vector<int>> d(h, vector<int>(w, -1));
      queue<pair<int, int>> wa;
      auto kyu = [&](int a, int b, int x) {
        if (d[a][b] != -1) return;
        d[a][b] = x;
        wa.push(pair<int, int>(a, b));
      };
      kyu(i, j, 0);
      while (!wa.empty()) {
        int nowi = wa.front().first;
        int nowj = wa.front().second;
        wa.pop();
        for (int dir = 0; dir < 4; dir++) {
          int ni = nowi + p[dir];
          int nj = nowj + v[dir];
          if (ni < 0 || ni >= h || nj < 0 || nj >= w) continue;
          if (s[ni][nj] == '#') continue;
          if (d[ni][nj] == -1) continue;
          kyu(ni, nj, d[nowi][nowj] + 1);
        }
      }
      for (int aa = 0; aa < h; aa++)
        for (int bb = 0; bb < w; bb++) {
          ans = max(ans, d[aa][bb]);
        }
    }
  cout << ans << endl;
  return 0;
}
