#include <bits/stdc++.h>
using namespace std;
int h, w, n, mx, d[405][405];
char b[25][25];
void f(int p, int q) { d[p][q] = d[q][p] = 1; }
int main() {
  int i, j, k;
  cin >> h >> w;
  for (i = 0; i < h; i++) cin >> b[i];
  n = h * w;
  for (i = 0; i < n; i++)
    for (j = 0; j < n; j++)
      if (i != j) d[i][j] = 1e9;
  for (i = 0; i < h; i++)
    for (j = 0; j < w; j++) {
      if (b[i][j] == '.' && b[i][j + 1] == '.') f(i * h + j, i * h + j + 1);
      if (b[i][j] == '.' && b[i + 1][j] == '.') f(i * h + j, (i + 1) * h + j);
    }
  for (k = 0; k < n; k++)
    for (i = 0; i < n; i++)
      for (j = 0; j < n; j++) {
        d[i][j] = min(d[i][j], d[i][k] + d[k][j]);
      }
  for (i = 0; i < n; i++)
    for (j = 0; j < n; j++) {
      if (d[i][j] < 1e9) mx = max(mx, d[i][j]);
    }
  cout << mx;
  return 0;
}
