#include <bits/stdc++.h>
using namespace std;
const long long MOD = 1000000007LL;
const long long INF = 1LL << 60;
using vll = vector<long long>;
using vb = vector<bool>;
using vvb = vector<vb>;
using vvll = vector<vll>;
using vstr = vector<string>;
using pair<long long, long long> = pair<long long, long long>;
const int di[] = {0, -1, 0, 1};
const int dj[] = {-1, 0, 1, 0};
int main() {
  long long h, w;
  cin >> h >> w;
  vstr ta(h);
  long long ans = 0;
  for (long long i = 0; i < (h); i++) cin >> ta[i];
  for (long long si = 0; si < (h); si++)
    for (long long sj = 0; sj < (w); sj++) {
      if (ta[si][sj] == '#') continue;
      vvll dist(h, vll(w, INF));
      queue<pair<long long, long long> > q;
      auto jj = [&](int i, int j, int x) {
        if (dist[i][j] != INF) return;
        dist[i][j] = x;
        q.push(pair<long long, long long>(i, j));
      };
      jj(si, sj, 0);
      while (!q.empty()) {
        long long i = q.front().first;
        long long j = q.front().second;
        q.pop();
        for (long long dir = 0; dir < (4); dir++) {
          long long ni = i + di[dir], nj = j + dj[i];
          if (ni < 0 || ni >= h || nj < 0 || nj >= w) continue;
          if (ta[ni][nj] == '#') continue;
          jj(ni, nj, dist[i][j] + 1);
        }
      }
      for (long long i = 0; i < (h); i++)
        for (long long j = 0; j < (w); j++) {
          if (ta[i][j] == '#') continue;
          ans = max(ans, dist[i][j]);
        }
    }
  cout << (ans) << endl;
}
