#include <bits/stdc++.h>
using namespace std;
const int dh[4] = {1, 0, -1, 0};
const int dw[4] = {0, 1, 0, -1};
int main() {
  int H, W;
  cin >> H >> W;
  vector<string> field(H);
  for (int h = 0; h < H; h++) {
    cin >> field[h];
  }
  int ans = 0;
  for (int h = 0; h < H; h++) {
    for (int w = 0; w < W; w++) {
      queue<int> que;
      que.push(h + w * H);
      vector<vector<int> > dist(H, vector<int>(W, -1));
      dist[h][w] = 0;
      while (!que.empty()) {
        int curh = que.front() % H;
        int curw = que.front() / H;
        que.pop();
        ans = max(ans, dist[curh][curw]);
        for (int i = 0; i < 4; i++) {
          if (curh + dh[i] < 0 || curh + dh[i] >= H || curw + dw[i] < 0 ||
              curw + dw[i] >= W)
            continue;
          if (field[curh + dh[i]][curw + dw[i]] == '#') continue;
          if (dist[curh + dh[i]][curw + dw[i]] != -1) continue;
          dist[curh + dh[i]][curw + dw[i]] = dist[curh][curw] + 1;
          que.push((curh + dh[i]) + (curw + dw[i]) * H);
        }
      }
    }
  }
  cout << ans << endl;
  return 0;
}
