#include <bits/stdc++.h>
using namespace std;
const int inf = 1e9 + 7;
const long long longinf = 1LL << 60;
const long long mod = 1e9 + 7;
int dx[] = {0, 1};
int dy[] = {1, 0};
vector<vector<int> > dist;
void warshall_floyd(int n) {
  for (int i = (int)(0); i < (int)(n); i++)
    for (int j = (int)(0); j < (int)(n); j++)
      for (int k = (int)(0); k < (int)(n); k++)
        dist[j][k] = min(dist[j][k], dist[j][i] + dist[i][k]);
}
int main() {
  int H, W;
  cin >> H >> W;
  vector<string> S(H);
  for (int i = (int)(0); i < (int)(H); i++) cin >> S[i];
  dist = vector<vector<int> >(H * W, vector<int>(H * W, inf));
  for (int i = (int)(0); i < (int)(H); i++)
    for (int j = (int)(0); j < (int)(W); j++) {
      if (S[i][j] == '.') {
        for (int k = (int)(0); k < (int)(2); k++) {
          int nx = i + dx[k];
          int ny = j + dy[k];
          if (nx < H && ny < W && S[nx][ny] == '.') {
            dist[i * W + j][nx * W + ny] = 1;
            dist[nx * W + ny][i * W + j] = 1;
          }
        }
      }
    }
  warshall_floyd(H * W);
  int ans = 0;
  for (int i = (int)(0); i < (int)(H * W); i++)
    for (int j = (int)(0); j < (int)(H * W); j++)
      if (dist[i][j] != inf) ans = max(dist[i][j], ans);
  cout << ans << endl;
  return 0;
}
