#include <bits/stdc++.h>
using namespace std;
int H, W;
int N;
int INF = 1e9;
void warshall_floyd(vector<vector<int>>& dist) {
  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 main() {
  cin >> H >> W;
  N = H * W;
  vector<vector<int>> dist(N, vector<int>(N, INF));
  string s;
  vector<string> S(H);
  for (int i = 0; i < H; i++) {
    cin >> S[i];
    for (int j = 0; j < W; j++) {
      if (j) {
        if (S[i][j] == '.' & S[i][j - 1] == '.') {
          dist[i * W + j][i * W + j - 1] = 1;
          dist[i * W + j - 1][i * W + j] = 1;
        }
      }
      if (i) {
        if (S[i][j] == '.' && S[i - 1][j] == '.') {
          dist[i * W + j][(i - 1) * W + j] = 1;
          dist[(i - 1) * W + j][i * W + j] = 1;
        }
      }
    }
  }
  warshall_floyd(dist);
  int ans = 0;
  for (int i = 0; i < N; i++) {
    for (int j = i; j < N; j++) {
      if (dist[i][j] < INF) ans = max(ans, dist[i][j]);
    }
  }
  cout << ans << endl;
}
