#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using coord = pair<int, int>;
int dh[4] = {0, 1, 0, -1};
int dw[4] = {1, 0, -1, 0};
int H, W;
int bfs(int h, int w, vector<string> S) {
  int ret = 0;
  vector<vector<int>> visited(H, vector<int>(W, -1));
  queue<coord> q;
  q.emplace(h, w);
  visited[h][w] = 0;
  while (!q.empty()) {
    int h = q.front().first;
    int w = q.front().second;
    q.pop();
    for (int i = 0; i < 4; i++) {
      if (h + dh[i] < 0 || h + dh[i] >= H || w + dw[i] < 0 || w - dw[i] >= W) {
        continue;
      }
      if (visited[h + dh[i]][w + dw[i]] != -1 ||
          S[h + dh[i]][w + dw[i]] == '#') {
        continue;
      }
      q.emplace(h + dh[i], w + dw[i]);
      visited[h + dh[i]][w + dw[i]] = visited[h][w] + 1;
      if (visited[h + dh[i]][w + dw[i]] > ret) {
        ret = visited[h + dh[i]][w + dw[i]];
      }
    }
  }
  return ret;
}
int main() {
  cin >> H >> W;
  vector<string> S(H);
  for (int i = 0; i < H; i++) {
    cin >> S[i];
  }
  int output = 0;
  for (int h = 0; h < H; h++) {
    for (int w = 0; w < W; w++) {
      int ret = 0;
      if (S[h][w] == '.') {
        ret = bfs(h, w, S);
      }
      if (ret > output) {
        output = ret;
      }
    }
  }
  cout << output << endl;
  return 0;
}
