#include <bits/stdc++.h>
using ll = long long;
using namespace std;
int main() {
  int H, W;
  cin >> H >> W;
  vector<string> M(H);
  for (int i = 0; i < (H); i++) cin >> M[i];
  int alp = H * W;
  vector<vector<int>> g(alp, vector<int>(alp, 1e9));
  for (int y = 0; y < (H); y++) {
    for (int x = 0; x < (W); x++) {
      if (x == W - 1) continue;
      if (M[y][x] == '.' && M[y][x + 1] == '.') {
        g[y * W + x][y * W + x + 1] = g[y * W + x + 1][y * W + x] = 1;
      }
    }
  }
  for (int x = 0; x < (W); x++) {
    for (int y = 0; y < (H); y++) {
      if (y == H - 1) continue;
      if (M[y][x] == '.' && M[y + 1][x] == '.') {
        g[y * W + x][(y + 1) * W + x] = g[(y + 1) * W + x][y * W + x] = 1;
      }
    }
  }
  for (int k = 0; k < (alp); k++)
    for (int i = 0; i < (alp); i++)
      for (int j = 0; j < (alp); j++) g[i][j] = min(g[i][j], g[i][k] + g[k][j]);
  int ans = 0;
  for (int y = 0; y < (alp); y++) {
    for (int x = 0; x < (alp); x++) {
      if (g[y][x] != 1e9) {
        ans = max(ans, g[y][x]);
      }
    }
  }
  cout << ans << endl;
  return 0;
}
