#include <bits/stdc++.h>
using namespace std;
const long long LINF = 1001002003004005006ll;
const int INF = 1001001001;
const int mod = 1000000007;
int h, w;
int main() {
  cin >> h >> w;
  vector<string> f(h);
  for (int i = 0; i < (h); ++i) cin >> f[i];
  int dx[4] = {1, 0, -1, 0};
  int dy[4] = {0, 1, 0, -1};
  int ans = 0;
  int d[h][w];
  for (int sh = 0; sh < (h); ++sh) {
    for (int sw = 0; sw < (w); ++sw) {
      if (f[sh][sw] == '#')
        continue;
      else {
        queue<pair<int, int> > q;
        q.push(pair<int, int>(sh, sw));
        for (int i = 0; i < (h); ++i)
          for (int j = 0; j < (w); ++j) d[i][j] = INF;
        d[sh][sw] = 0;
        while (q.size() != 0) {
          pair<int, int> pos = q.front();
          q.pop();
          for (int i = 0; i < (4); ++i) {
            int nh = pos.first + dy[i];
            int nw = pos.second + dx[i];
            if (nh < 0 | nh >= h | nw < 0 | nw >= w | f[nh][nw] != '.' |
                d[nh][nw] != INF)
              continue;
            d[nh][nw] = d[pos.first][pos.second] + 1;
            q.push(pair<int, int>(nh, nw));
            ans = max(ans, d[nh][nw]);
          }
        }
      }
    }
  }
  cout << ans << endl;
  return 0;
}
