#include <bits/stdc++.h>
#pragma GCC optimize("O3")
using namespace std;
ifstream fin("spioni.in");
ofstream fout("spioni.out");
int dl[4] = {0, 0, -1, 1};
int dc[4] = {1, -1, 0, 0};
int n, m, t[23][23], mat[402][402], nr;
char v[23][23];
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  cin >> n >> m;
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= m; j++) cin >> v[i][j];
  }
  for (int i = 1; i <= n; i++)
    for (int j = 1; j <= m; j++) {
      if (v[i][j] != '.') continue;
      nr++;
      t[i][j] = nr;
      for (int k = 0; k < 4; k++) {
        int ii = i + dl[k];
        int jj = j + dc[k];
        if (v[ii][jj] == '.' && t[ii][jj]) {
          mat[nr][t[ii][jj]] = 1;
          mat[t[ii][jj]][nr] = 1;
        }
      }
    }
  for (int i = 1; i <= nr; i++)
    for (int j = 1; j <= nr; j++)
      if (mat[i][j] == 0) mat[i][j] = 1e9;
  for (int k = 1; k <= nr; k++)
    for (int i = 1; i <= nr; i++)
      for (int j = 1; j <= nr; j++) {
        if (mat[i][k] + mat[k][j] < mat[i][j])
          mat[i][j] = mat[i][k] + mat[k][j];
      }
  int mx = 0;
  for (int i = 1; i <= nr; i++)
    for (int j = 1; j <= nr; j++) mx = max(mx, mat[i][j]);
  cout << mx;
  return 0;
}
