#include <bits/stdc++.h>
using namespace std;
vector<pair<string, pair<int, int> > > vec;
long long d[301][301];
long long N;
void warshall_floyd() {
  for (int k = 0; k < N; k++)
    for (int i = 0; i < N; i++)
      for (int j = 0; j < N; j++) d[i][j] = min(d[i][j], d[i][k] + d[k][j]);
}
int main() {
  long long H;
  long long W;
  scanf("%lld", &H);
  vector<string> S(H - 1 + 1);
  scanf("%lld", &W);
  for (int i = 0; i <= H - 1; i++) {
    cin >> S[i];
  }
  for (int i = 0; i <= 301 - 1; i++) {
    for (int j = 0; j <= 301 - 1; j++) {
      if (i == j)
        d[i][j] = 0;
      else
        d[i][j] = 10000000000001;
    }
  }
  for (long long i = 0; i < H; i++) {
    for (long long j = 0; j < W; j++) {
      if (i > 0 && S[i][j] == '.' && S[i - 1][j] == '.') {
        long long f = i * W + j, t = (i - 1) * W + j;
        d[f][t] = 1;
        d[t][f] = 1;
      }
      if (j > 0 && S[i][j] == '.' && S[i][j - 1] == '.') {
        long long f = i * W + j, t = i * W + j - 1;
        d[f][t] = 1;
        d[t][f] = 1;
      }
      if (i < H - 1 && S[i][j] == '.' && S[i + 1][j] == '.') {
        long long f = i * W + j, t = (i + 1) * W + j;
        d[f][t] = 1;
        d[t][f] = 1;
      }
      if (j < W - 1 && S[i][j] == '.' && S[i][j + 1] == '.') {
        long long f = i * W + j, t = i * W + j + 1;
        d[f][t] = 1;
        d[t][f] = 1;
      }
    }
  }
  N = H * W;
  warshall_floyd();
  long long res = 0;
  for (long long i = 0; i < H * W; i++) {
    for (long long j = 0; j < H * W; j++) {
      if (d[i][j] < 10000000000001) res = max(res, d[i][j]);
    }
  }
  cout << res << endl;
  return 0;
}
