#include <bits/stdc++.h>
using namespace std;
const int inf = 1 << 29;
const long long INF = 1ll << 60;
const double pi = acos(-1);
const double eps = 1e-9;
const long long mod = 1e9 + 7;
const int dx[4] = {-1, 0, 1, 0}, dy[4] = {0, -1, 0, 1};
int h, w;
vector<string> a;
int main() {
  cin >> h >> w;
  a = vector<string>(h);
  int n = h * w;
  vector<vector<int> > g(n, vector<int>(n, inf));
  for (int i = 0; i < h; i++) cin >> a[i];
  for (int i = 0; i < h; i++)
    for (int j = 0; j < w; j++) {
      for (int k = 0; k < 4; k++) {
        int x = i + dx[k], y = j + dy[k];
        if (x >= 0 && x < h && y >= 0 && y < w && a[x][y] == '.') {
          g[i * w + j][x * w + y] = 1;
        }
      }
      g[i * w + j][i * w + j] = 0;
    }
  for (int k = 0; k < n; k++)
    for (int i = 0; i < n; i++)
      for (int j = 0; j < n; j++) g[i][j] = min(g[i][j], g[i][k] + g[k][j]);
  int res = 0;
  for (int i = 0; i < n; i++)
    for (int j = 0; j < n; j++)
      if (g[i][j] < inf) res = max(res, g[i][j]);
  cout << res << endl;
}
