#include <bits/stdc++.h>
using namespace std;
using vi = vector<int>;
using vv = vector<vi>;
using P = pair<int, int>;
int main() {
  int h, w;
  cin >> h >> w;
  vector<string> s(h);
  for (int i = 0; i < (h); ++i) cin >> s[i];
  vi di = {0, 1, 0, -1};
  vi dj = {1, 0, -1, 0};
  int ans = 0;
  for (int i = 0; i < (h); ++i)
    for (int j = 0; j < (w); ++j) {
      vv check(h, vi(w, -1));
      queue<P> q;
      q.push(P(i, j));
      check[i][j] = 0;
      while (!q.empty()) {
        int pi = q.front().first;
        int pj = q.front().second;
        q.pop();
        int nc = check[pi][pj] + 1;
        for (int a = 0; a < (4); ++a) {
          int ni = pi + di[a];
          int nj = pj + dj[a];
          if (ni < 0 || nj < 0 || ni >= h || nj >= w) continue;
          if (s[ni][nj] == '#') continue;
          if (check[ni][nj] != -1) continue;
          check[ni][nj] = nc;
          q.push(P(ni, nj));
          ans = max(ans, nc);
        }
      }
    }
  cout << ans << endl;
  return 0;
}
