#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int inf = 1e9 + 7;
const ll longinf = 1LL << 60;
const ll mod = 1e9 + 7;
int main() {
  int H, W;
  cin >> H >> W;
  vector<string> S(H);
  for (int i = 0; i < W; i++) cin >> S[i];
  ll d[H * W][H * W];
  for (int h = 0; h < H * W; h++) {
    for (int w = 0; w < H * W; w++) {
      if (h == w)
        d[h][w] = 0;
      else
        d[h][w] = inf;
    }
  }
  for (int h = 1; h < H; h++) {
    for (int w = 0; w < W; w++) {
      if (S[h - 1][w] == '.' && S[h][w] == '.') {
        d[w + (h - 1) * W][w + h * W] = 1;
        d[w + h * W][w + (h - 1) * W] = 1;
      }
    }
  }
  for (int h = 0; h < H; h++) {
    for (int w = 1; w < W; w++) {
      if (S[h][w - 1] == '.' && S[h][w] == '.') {
        d[w - 1 + h * W][w + h * W] = 1;
        d[w + h * W][w - 1 + h * W] = 1;
      }
    }
  }
  for (int k = 0; k < H * W; k++) {
    for (int i = 0; i < H * W; i++) {
      for (int j = 0; j < H * W; j++) {
        d[i][j] = min(d[i][j], d[i][k] + d[k][j]);
      }
    }
  }
  ll ans = 0;
  for (int h = 0; h < H * W; h++) {
    for (int w = 0; w < H * W; w++) {
      if (d[h][w] != inf) ans = max(ans, d[h][w]);
    }
  }
  cout << ans << "\n";
  return 0;
}
