#include <bits/stdc++.h>
using namespace std;
int d[400][400];
const int INF = 123456;
int main() {
  int h, w;
  cin >> h >> w;
  vector<string> v(h);
  for (int i = (int)(0); i < (int)(h); i++) cin >> v[i];
  auto id = [&](int x, int y) { return x * h + y; };
  int n = h * w;
  for (int i = (int)(0); i < (int)(n); i++)
    for (int j = (int)(0); j < (int)(n); j++) d[i][j] = INF;
  for (int i = (int)(0); i < (int)(n); i++) d[i][i] = 0;
  const int ki[] = {-1, 1, 0, 0};
  const int kj[] = {0, 0, -1, 1};
  for (int i = (int)(0); i < (int)(h); i++)
    for (int j = (int)(0); j < (int)(w); j++)
      if (v[i][j] == '.') {
        for (int k = (int)(0); k < (int)(4); k++) {
          int ni = i + ki[k], nj = j + kj[k];
          if (ni < 0 || ni >= h || nj < 0 || nj >= w) continue;
          if (v[ni][nj] == '#') continue;
          d[id(i, j)][id(ni, nj)] = 1;
        }
      }
  for (int k = (int)(0); k < (int)(n); k++)
    for (int i = (int)(0); i < (int)(n); i++)
      for (int j = (int)(0); j < (int)(n); j++)
        d[i][j] = min(d[i][j], d[i][k] + d[k][j]);
  int ans = 0;
  for (int i = (int)(0); i < (int)(n); i++)
    for (int j = (int)(0); j < (int)(n); j++)
      if (d[i][j] < INF) ans = max(ans, d[i][j]);
  cout << ans << endl;
  return 0;
}
