#include <bits/stdc++.h>
using namespace std;
const int INF = 1 << 29;
const long long INFL = 1LL << 60;
const long long mod = 1000000007;
char c[20][20];
vector<int> dx = {1, -1, 0, 0};
vector<int> dy = {0, 0, 1, -1, 1};
long long ans[400][400];
int main() {
  int h, w;
  cin >> h >> w;
  for (long long i = 0; i < long long(h); i++)
    for (long long j = 0; j < long long(w); j++) cin >> c[i][j];
  for (long long i = 0; i < long long(400); i++)
    for (long long j = 0; j < long long(400); j++) ans[i][j] = INF;
  for (long long i = 0; i < long long(h); i++)
    for (long long j = 0; j < long long(w); j++) {
      if (c[i][j] == '#') continue;
      int a = i * w + j;
      for (long long k = 0; k < long long(4); k++) {
        int ny = i + dy[k], nx = j + dx[k];
        if (ny < 0 || h <= ny || nx < 0 || w <= nx) continue;
        if (c[ny][nx] == '#') continue;
        int b = ny * w + nx;
        ans[a][b] = 1;
      }
    }
  for (long long _ = 0; _ < long long(3); _++) {
    for (long long i = 0; i < long long(400); i++) {
      for (long long j = 0; j < long long(400); j++) {
        for (long long k = 0; k < long long(400); k++) {
          ans[j][k] = min(ans[j][k], ans[j][i] + ans[i][k]);
        }
      }
    }
  }
  long long an = 0;
  for (long long i = 0; i < long long(400); i++)
    for (long long j = 0; j < long long(400); j++) {
      if (ans[i][j] == INF) continue;
      an = max(an, ans[i][j]);
    }
  cout << an << endl;
}
