#include <bits/stdc++.h>
using namespace std;
const long long INF = 1LL << 60;
int main() {
  int H, W;
  cin >> H >> W;
  vector<string> maze(H);
  for (int i = 0; i < (H); ++i) cin >> maze[i];
  int K = H * W;
  int G[K][K];
  for (int i = 0; i < (K); ++i) {
    for (int j = 0; j < (K); ++j) G[i][j] = 1 << 20;
    G[i][i] = 0;
  }
  vector<int> di = {1, 0, -1, 0}, dj = {0, 1, 0, -1};
  for (int i = 0; i < (H); ++i)
    for (int j = 0; j < (W); ++j) {
      if (maze[i][j] == '#') continue;
      for (int k = 0; k < (4); ++k) {
        int ni = i + di[k];
        int nj = j + dj[k];
        if (0 <= ni && ni < H && 0 <= nj && nj < W && maze[ni][nj] == '.')
          G[H * i + j][H * ni + nj] = 1;
      }
    }
  for (int k = 0; k < (K); ++k)
    for (int i = 0; i < (K); ++i)
      for (int j = 0; j < (K); ++j) G[i][j] = min(G[i][j], G[i][k] + G[k][j]);
  int ans = 0;
  for (int i = 0; i < (K); ++i)
    for (int j = 0; j < (K); ++j) {
      if (G[i][j] != (1 << 20)) ans = max(ans, G[i][j]);
    }
  cout << ans << endl;
}
