#include <bits/stdc++.h>
using namespace std;
const int INF = 10000;
int dx[] = {1, 0, -1, 0}, dy[] = {0, 1, 0, -1};
int main() {
  int n, m;
  scanf("%d%d", &n, &m);
  char grid[n][m];
  int dist[500][500];
  for (int i = 0; i < n; i++) {
    scanf("%s", grid[i]);
  }
  for (int i = 0; i < 500; i++)
    for (int j = 0; j < 500; j++) dist[i][j] = INF;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      if (grid[i][j] != '.') continue;
      int X = i * m + j;
      if (i) {
        if (grid[i - 1][j] == '.') {
          dist[X - m][X] = dist[X][X - m] = 1;
        }
      }
      if (j) {
        if (grid[i][j - 1] == '.') {
          dist[X - 1][X] = dist[X][X - 1] = 1;
        }
      }
    }
  }
  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++) {
      if (dist[i][j] != INF) {
        ans = max(ans, dist[i][j]);
      }
    }
  }
  printf("%d", ans);
}
