#include <bits/stdc++.h>
using namespace std;
long long INFl = 1e+18 + 1;
int INF = 1e+9 + 1;
int main() {
  int H, W;
  char S[25][25];
  cin >> H >> W;
  int A[401][401];
  fill(A[0], A[401], INF);
  for (int i = 0; i < H; i++) {
    cin >> S[i];
  }
  int N = H * W;
  for (int i = 0; i < H; i++) {
    for (int j = 0; j < W - 1; j++) {
      if (S[i][j] == '.' && S[i][j + 1] == '.')
        A[i * W + j][i * W + j + 1] = 1, A[i * W + j + 1][i * W + j] = 1;
    }
  }
  for (int j = 0; j < W; j++) {
    for (int i = 0; i < H - 1; i++) {
      if (S[i][j] == '.' && S[i + 1][j] == '.')
        A[i * W + j][(i + 1) * W + j] = 1, A[(i + 1) * W + j][i * W + j] = 1;
    }
  }
  for (int k = 0; k < N; k++) {
    for (int i = 0; i < N; i++) {
      for (int j = 0; j < N; j++) {
        if (k == i || k == j) continue;
        if (A[i][j] > A[i][k] + A[k][j]) A[i][j] = A[i][k] + A[k][j];
      }
    }
  }
  int ans = 0;
  for (int i = 0; i < N; i++) {
    for (int j = 0; j < N; j++) {
      if (A[i][j] != INF) ans = max(ans, A[i][j]);
    }
  }
  cout << ans << endl;
  return 0;
}
