#include <bits/stdc++.h>
using namespace std;
const long long MOD = 1e9 + 7;
const long long INF = MOD * MOD;
int main() {
  int h, w;
  cin >> h >> w;
  string s[h];
  for (int(i) = 0; (i) < (h); (i)++) cin >> s[i];
  long long ans = 0;
  for (int(i) = 0; (i) < (h); (i)++)
    for (int(j) = 0; (j) < (w); (j)++) {
      if (s[i][j] == '#') continue;
      long long d[h][w];
      for (int(x) = 0; (x) < (h); (x)++)
        for (int(y) = 0; (y) < (w); (y)++) d[x][y] = INF;
      d[i][j] = 0;
      queue<pair<long long, long long> > q;
      q.push(make_pair(i, j));
      while (!q.empty()) {
        pair<long long, long long> t = q.front();
        q.pop();
        vector<pair<long long, long long> > vp;
        if (t.first > 0) vp.push_back(make_pair(t.first - 1, t.second));
        if (t.first < h - 1) vp.push_back(make_pair(t.first + 1, t.second));
        if (t.second > 0) vp.push_back(make_pair(t.first, t.second - 1));
        if (t.second < w - 1) vp.push_back(make_pair(t.first, t.second + 1));
        for (int(k) = 0; (k) < (vp.size()); (k)++) {
          if (s[vp[k].first][vp[k].second] == '#' ||
              d[vp[k].first][vp[k].second] < INF)
            continue;
          d[vp[k].first][vp[k].second] = d[t.first][t.second] + 1;
          q.push(vp[k]);
        }
      }
      long long res = 0;
      for (int(i) = 0; (i) < (h); (i)++)
        for (int(j) = 0; (j) < (w); (j)++) {
          if (d[i][j] != INF) res = max(res, d[i][j]);
        }
      ans = max(ans, res);
    }
  cout << ans << endl;
}
