#include <bits/stdc++.h>
using namespace std;
const double PI = acos(-1);
const double EPS = 1e-9;
long long gcd(long long a, long long b) {
  if (b == 0) return a;
  return gcd(b, a % b);
}
long long lcm(long long a, long long b) { return a / gcd(a, b) * b; }
long long h, w;
long long f(long long a, long long b) { return a * w + b; }
bool in(long long a, long long b) {
  if (a < 0 || a >= h || b < 0 || b >= w) return false;
  return true;
}
long long dx[] = {0, 1, 0, -1};
long long dy[] = {1, 0, -1, 0};
signed main(void) {
  cin >> h >> w;
  vector<string> s(h);
  for (long long i = 0; i < (h); i++) cin >> s[i];
  long long dp[30 * 30][30 * 30] = {};
  for (long long i = 0; i < (30 * 30); i++)
    for (long long j = 0; j < (30 * 30); j++)
      if (i != j) dp[i][j] = 1e9;
  for (long long i = 0; i < (h); i++)
    for (long long j = 0; j < (w); j++) {
      for (long long k = 0; k < (4); k++) {
        long long x = i + dx[k];
        long long y = j + dy[k];
        if (!in(x, y)) continue;
        if (s[x][y] == '#') continue;
        dp[f(i, j)][f(x, y)] = 1;
      }
    }
  for (long long k = 0; k < (h * w); k++)
    for (long long i = 0; i < (h * w); i++)
      for (long long j = 0; j < (h * w); j++) {
        dp[i][j] = min(dp[i][j], dp[i][k] + dp[k][j]);
      }
  long long ans = 0;
  for (long long i = 0; i < (30 * 30); i++)
    for (long long j = 0; j < (30 * 30); j++)
      if (dp[i][j] != 1e9) {
        ans = max(ans, dp[i][j]);
      }
  cout << ans << endl;
}
