#include <bits/stdc++.h>
using namespace std;
using LP = pair<long long, long long>;
using P = pair<int, int>;
const int inf = 500;
int h, w;
char g[21][21];
int main() {
  cin >> h >> w;
  for (int i = 0; i < h; i++)
    for (int j = 0; j < w; j++) cin >> g[i][j];
  auto toId = [&](int x, int y) { return x * w + y; };
  int n = h * w;
  vector<vector<int>> dist(n, vector<int>(n, inf));
  for (int i = 0; i < n; i++) {
    if (g[i / w][i % w] == '#') continue;
    for (int j = 0; j < n; j++) {
      if (g[j / w][j % w] == '#') continue;
      if (i == j) dist[i][j] = 0;
      if (abs(i - j) == 1 or abs(i - j) == w) dist[i][j] = 1;
    }
  }
  for (int k = 0; k < n; k++) {
    if (g[k / w][k % w] == '#') continue;
    for (int i = 0; i < n; i++) {
      if (g[i / w][i % w] == '#') continue;
      for (int j = 0; j < n; j++) {
        if (g[j / w][j % w] == '#') continue;
        dist[i][j] = min(dist[i][j], dist[i][k] + dist[k][j]);
      }
    }
  }
  int ans = 0;
  for (int i = 0; i < n; i++)
    for (int j = 0; j < n; j++) {
      if (dist[i][j] == inf) continue;
      ans = max(ans, dist[i][j]);
    }
  cout << ans << endl;
}
