#include <bits/stdc++.h>
using namespace std;
void moveNum(char* S, int* N, int ph, int pw, int h, int w) {
  if (S[w * (ph + 1) + pw] == '.' && ph < (h - 1) &&
      N[w * (ph + 1) + pw] > N[w * ph + pw] + 1) {
    N[w * (ph + 1) + pw] = N[w * ph + pw] + 1;
    moveNum(S, N, ph + 1, pw, h, w);
  }
  if (S[w * (ph - 1) + pw] == '.' && ph > 0 &&
      N[w * (ph - 1) + pw] > N[w * ph + pw] + 1) {
    N[w * (ph - 1) + pw] = N[w * ph + pw] + 1;
    moveNum(S, N, ph - 1, pw, h, w);
  }
  if (S[w * ph + (pw + 1)] == '.' && pw < (w - 1) &&
      N[w * ph + (pw + 1)] > N[w * ph + pw] + 1) {
    N[w * ph + (pw + 1)] = N[w * ph + pw] + 1;
    moveNum(S, N, ph, pw + 1, h, w);
  }
  if (S[w * ph + (pw - 1)] == '.' && pw > 0 &&
      N[w * ph + (pw - 1)] > N[w * ph + pw] + 1) {
    N[w * ph + (pw - 1)] = N[w * ph + pw] + 1;
    moveNum(S, N, ph, pw - 1, h, w);
  }
}
int main() {
  int h, w, ph, pw, ans = -1, moveMax;
  cin >> h >> w;
  char S[h * w];
  for (int i = 0; i < h * w; i++) {
    cin >> S[i];
  }
  int N[h * w];
  for (int i = 0; i < h * w; i++) {
    moveMax = -1;
    for (int i = 0; i < h * w; i++) {
      N[i] = 100;
    }
    ph = i / w;
    pw = i % w;
    N[ph * w + pw] = 0;
    moveNum(S, N, ph, pw, h, w);
    for (int i = 0; i < h * w; i++) {
      if (N[i] != 100) {
        moveMax = max(moveMax, N[i]);
      }
    }
    ans = max(ans, moveMax);
  }
  cout << ans << endl;
  return 0;
}
