#include <bits/stdc++.h>
using namespace std;
int main() {
  int H, W, ans = 0;
  cin >> H >> W;
  vector<string> S(H);
  for (auto& i : S) cin >> i;
  const int dh[] = {1, -1, 0, 0}, dw[] = {0, 0, 1, -1};
  vector<vector<bool>> visited(H, vector<bool>(W, false));
  queue<tuple<int, int, int>> q;
  for (int sh = 0; sh < H; sh++) {
    for (int sw = 0; sw < W; sw++) {
      if (S[sh][sw] == '#') continue;
      visited[sh][sw] = true;
      q.push({sh, sw, 0});
      while (!q.empty()) {
        int ch = get<0>(q.front()), cw = get<1>(q.front()),
            cc = get<2>(q.front());
        if (cc > ans) ans = cc;
        q.pop();
        for (int i = 0; i < 4; i++) {
          int nh = ch + dh[i], nw = cw + dw[i];
          if (nh < 0 || nh >= H || nw < 0 || nw >= W) continue;
          if (S[nh][nw] == '#' || visited[nh][nw] == true) continue;
          visited[nh][nw] = true;
          q.push({nh, nw, cc + 1});
        }
      }
      for (size_t i = 0; i < visited.size(); i++)
        for (size_t j = 0; j < visited[i].size(); j++) visited[i][j] = false;
    }
  }
  cout << ans << endl;
}
