#include <bits/stdc++.h>
using namespace std;
using ll = long long;
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];
  int di[] = {-1, 1, 0, 0};
  int dj[] = {0, 0, -1, 1};
  int mita[20][20];
  int mx = 0;
  for (int si = 0; si < (h); ++si)
    for (int sj = 0; sj < (w); ++sj) {
      if (s[si][sj] == '#') continue;
      queue<P> q, nq;
      q.push(make_pair(si, sj));
      for (int i = 0; i < (h); ++i)
        for (int j = 0; j < (w); ++j) mita[i][j] = false;
      int cnt = 0;
      while (!q.empty()) {
        while (!q.empty()) {
          P p = q.front();
          q.pop();
          int ci = p.first, cj = p.second;
          for (int k = 0; k < (4); ++k) {
            int ni = ci + di[k], nj = cj + dj[k];
            if (0 <= ni && ni < h && 0 <= nj && nj < w)
              if (s[ni][nj] == '.')
                if (!mita[ni][nj]) {
                  mita[ni][nj] = true;
                  nq.push(make_pair(ni, nj));
                }
          }
        }
        if (!nq.empty()) cnt++;
        swap(q, nq);
      }
      mx = max(mx, cnt);
    }
  cout << mx << endl;
  return 0;
}
