#include <bits/stdc++.h>
using namespace std;
int H, W;
string S[20];
int A[400][400];
void solve() {
  int i, j, k, l, r, x, y;
  string s;
  cin >> H >> W;
  for (x = 0; x < (400); x++)
    for (y = 0; y < (400); y++) A[x][y] = (x == y) ? 0 : 101010;
  for (y = 0; y < (H); y++) cin >> S[y];
  for (y = 0; y < (H); y++) {
    for (x = 0; x < (W); x++)
      if (S[y][x] == '.') {
        if (x && S[y][x - 1] == '.')
          A[y * 20 + x - 1][y * 20 + x] = A[y * 20 + x][y * 20 + x - 1] = 1;
        if (y && S[y - 1][x] == '.')
          A[y * 20 + x - 20][y * 20 + x] = A[y * 20 + x][y * 20 + x - 20] = 1;
      }
  }
  for (i = 0; i < (400); i++)
    for (x = 0; x < (400); x++)
      for (y = 0; y < (400); y++) A[x][y] = min(A[x][y], A[x][i] + A[i][y]);
  int ma = 0;
  for (y = 0; y < (400); y++)
    for (x = 0; x < (100); x++)
      if (A[x][y] != 101010) ma = max(ma, A[x][y]);
  cout << ma << endl;
}
int main(int argc, char** argv) {
  string s;
  int i;
  if (argc == 1) ios::sync_with_stdio(false), cin.tie(0);
  for (i = 0; i < (argc - 1); i++) s += argv[i + 1], s += '\n';
  for (i = 0; i < (s.size()); i++) ungetc(s[s.size() - 1 - i], stdin);
  cout.tie(0);
  solve();
  return 0;
}
