#include <bits/stdc++.h>
using namespace std;
const long long MOD = 998244353;
long long mpow(long long a, long long b, long long p = MOD) {
  a = a % p;
  long long res = 1;
  while (b > 0) {
    if (b & 1) res = (res * a) % p;
    a = (a * a) % p;
    b = b >> 1;
  }
  return res % p;
}
const long long N = 1e4 + 2;
long long dd[2] = {1, -1};
long long val[21][21];
long long d[404][404];
int32_t main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  long long h, w;
  cin >> h >> w;
  string s[h];
  for (long long i = 0; i < h; i++) cin >> s[i];
  long long cnt = 0;
  for (long long i = 0; i < 30; i++) {
    for (long long j = 0; j < 20; j++) {
      val[i][j] = cnt++;
    }
  }
  for (long long i = 0; i < 402; i++)
    for (long long j = 0; j < 402; j++) d[i][j] = 1e17;
  for (long long i = 0; i < 402; i++) d[i][i] = 0;
  for (long long i = 0; i < h; i++) {
    for (long long j = 0; j < w; j++) {
      if (i + 1 < h && s[i + 1][j] == '.') {
        d[val[i][j]][val[i + 1][j]] = 1;
      }
      if (j + 1 < w && s[i][j + 1] == '.') {
        d[val[i][j]][val[i][j + 1]] = 1;
      }
      if (i - 1 >= 0 && s[i - 1][j] == '.') {
        d[val[i][j]][val[i - 1][j]] = 1;
      }
      if (j - 1 >= 0 && s[i][j - 1] == '.') {
        d[val[i][j]][val[i][j - 1]] = 1;
      }
    }
  }
  for (long long k = 0; k < 402; k++) {
    for (long long i = 0; i < 402; i++) {
      for (long long j = 0; j < 402; j++) {
        d[i][j] = min(d[i][j], d[i][k] + d[k][j]);
      }
    }
  }
  long long ans = -1;
  for (long long i = 0; i < 402; i++)
    for (long long j = 0; j < 402; j++) {
      if (d[i][j] == 1e17) continue;
      ans = max(ans, d[i][j]);
    }
  cout << ans;
}
