#include <bits/stdc++.h>
using namespace std;
vector<vector<int>> g(401);
const int INF = 1e9;
int main() {
  int h, w;
  cin >> h >> w;
  char a[h][w];
  int d[401][401];
  for (int i = 0; i < 401; i++)
    for (int j = 0; j < 401; j++) d[i][j] = INF;
  for (int i = 0; i < h; i++) {
    string s;
    cin >> s;
    for (int j = 0; j < w; j++) a[i][j] = s[j];
  }
  for (int i = 0; i < h; i++) {
    for (int j = 0; j < w; j++) {
      if (a[i][j] == '.') {
        if (j < w - 1) {
          if (a[i][j + 1] == '.') {
            d[i * w + j][i * w + j + 1] = 1;
            d[i * w + j][(i)*w + j + 1] = 1;
          }
        }
        if (i < h - 1) {
          if (a[i + 1][j] == '.') {
            d[i * w + j][(i + 1) * w + j] = 1;
            d[(i + 1) * w + j][(i)*w + j] = 1;
          }
        }
      }
    }
  }
  int V = (h) * (w);
  for (int i = 0; i < V; i++)
    for (int j = 0; j < V; j++)
      for (int k = 0; k < V; k++)
        if (d[i][j] + d[i][k] < d[j][k]) d[j][k] = d[i][j] + d[i][k];
  int ans = -1;
  for (int i = 0; i < 401; i++)
    for (int j = 0; j < 401; j++)
      if (d[i][j] != INF) ans = max(ans, d[i][j]);
  cout << ans << endl;
  return 0;
}
