#include <bits/stdc++.h>
using namespace std;
using vi = vector<int>;
using vvi = vector<vi>;
using VC = vector<char>;
using VVC = vector<VC>;
void warshall_floyd(vvi &D) {
  for (int relay = (0); relay < (D.size()); ++relay)
    for (int from = (0); from < (D.size()); ++from)
      for (int to = (0); to < (D.size()); ++to)
        D[from][to] = min(D[from][to], D[from][relay] + D[relay][to]);
}
int main() {
  int H, W;
  cin >> H >> W;
  VVC S(H + 2, VC(W + 2, '#'));
  for (int h = (1); h < (H + 1); ++h) {
    string s;
    cin >> s;
    for (int w = (1); w < (W + 1); ++w)
      if (s[w - 1] == '.') S[h][w] = '.';
  }
  int N = H * W;
  vvi D(N, vi(N, 100000));
  int dx[4] = {0, -1, 0, 1}, dy[4] = {-1, 0, 1, 0};
  for (int ph = (1); ph < (H + 1); ++ph) {
    for (int pw = (1); pw < (W + 1); ++pw) {
      if (S[ph][pw] != '.') continue;
      int i = (ph - 1) * W + (pw - 1);
      for (int k = (0); k < (4); ++k) {
        int h = ph + dy[k], w = pw + dx[k];
        if (S[h][w] != '.') continue;
        int j = (h - 1) * W + (w - 1);
        if (i == j)
          D[i][j] = 0;
        else
          D[i][j] = D[j][i] = 1;
      }
    }
  }
  warshall_floyd(D);
  int ans = 0;
  for (int i = (0); i < (N); ++i) {
    for (int j = (0); j < (N); ++j) {
      if (D[i][j] != 100000) ans = max(ans, D[i][j]);
    }
  }
  cout << ans << endl;
}
