#include <bits/stdc++.h>
using namespace std;
const int dx[4] = {0, 0, 1, -1};
const int dy[4] = {1, -1, 0, 0};
signed main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int h, w;
  cin >> h >> w;
  vector<string> grid(h);
  for (int i = 0; i < h; i++) cin >> grid[i];
  int res = -1;
  for (int sh = 0; sh < h; sh++) {
    for (int sw = 0; sw < w; sw++) {
      if (grid[sh][sw] == '#') continue;
      queue<pair<int, int>> que;
      vector<vector<int>> dist(h, vector<int>(w, -1));
      dist[sh][sw] = 0;
      que.push({sh, sw});
      while (!que.empty()) {
        int vh = que.front().first;
        int vw = que.front().second;
        que.pop();
        for (int dir = 0; dir < 4; dir++) {
          int nvh = vh + dy[dir];
          int nvw = vw + dx[dir];
          if (nvh < 0) continue;
          if (nvw < 0) continue;
          if (nvh >= h) continue;
          if (nvh >= w) continue;
          if (dist[nvh][nvw] != -1) continue;
          if (grid[nvh][nvw] == '#') continue;
          dist[nvh][nvw] = dist[vh][vw] + 1;
          que.push({nvh, nvw});
        }
      }
      for (int i = 0; i < h; i++)
        res = max(res, (int)*max_element(dist[i].begin(), dist[i].end()));
    }
  }
  cout << res << endl;
  return 0;
}
