#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m;
  cin >> n >> m;
  vector<vector<bool>> g(n, vector<bool>(m));
  for (int i = 0; i < n; i++) {
    string s;
    cin >> s;
    for (int j = 0; j < m; j++) g[i][j] = s[j] == '.';
  }
  auto compress = [&](int i, int j) -> int { return i * m + j; };
  const int INF = 1 << 20;
  vector<vector<int>> dist(n * m, vector<int>(n * m, INF));
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m - 1; j++) {
      if (g[i][j] && g[i][j + 1]) dist[compress(i, j)][compress(i, j + 1)] = 1;
    }
  }
  for (int i = 0; i < n; i++)
    for (int j = 0; j < m; j++) dist[compress(i, j)][compress(i, j)] = 0;
  int N = n * m;
  for (int k = 0; k < N; k++) {
    for (int i = 0; i < N; i++) {
      for (int j = 0; j < N; j++) {
        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++) ans = max(ans, dist[i][j]);
  cout << ans << endl;
  return 0;
}
