#include <bits/stdc++.h>
using namespace std;
const long long MOD = 1e9 + 7;
const long long INF = 1e9 + 5;
char a[25][25];
int d[405][405];
int main() {
  for (int i = 0; i < 405; i++) {
    for (int j = 0; j < 405; j++) {
      d[i][j] = INF;
    }
  }
  int n, m;
  cin >> n >> m;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      cin >> a[i][j];
      if (a[i][j] == '.') {
        if (i and a[i - 1][j] == '.') {
          d[i * m + j][(i - 1) * m + j] = 1;
          d[(i - 1) * m + j][i * m + j] = 1;
        }
        if (j and a[i][j - 1] == '.') {
          d[i * m + j][i * m + j - 1] = 1;
          d[i * m + j - 1][i * m + j] = 1;
        }
      }
    }
  }
  for (int k = 0; k < 405; k++) {
    for (int i = 0; i < n * m; i++) {
      for (int j = 0; j < n * m; j++) {
        d[i][j] = min(d[i][j], d[i][k] + d[k][j]);
      }
    }
  }
  int sol = 0;
  for (int i = 0; i < n * m; i++) {
    for (int j = 0; j < n * m; j++) {
      if (d[i][j] != INF) {
        sol = max(sol, d[i][j]);
      }
    }
  }
  printf("%d\n", sol);
  return 0;
}
