#include <bits/stdc++.h>
using namespace std;
const int MAXH = 25;
const int MAXW = 25;
const int dirx[4] = {0, 0, 1, -1};
const int diry[4] = {-1, 1, 0, 0};
int h, w;
int dep[MAXH][MAXW];
char mp[MAXH][MAXW];
void dfs(int x, int y) {
  if (x <= 0 || y <= 0 || x > h || y > w) return;
  for (int i = 0; i < 4; i++) {
    if (mp[x + dirx[i]][y + diry[i]] == '.' &&
        (dep[x + dirx[i]][y + diry[i]] == -1 ||
         dep[x + dirx[i]][y + diry[i]] > dep[x][y] + 1)) {
      dep[x + dirx[i]][y + diry[i]] = dep[x][y] + 1;
      dfs(x + dirx[i], y + diry[i]);
    }
  }
}
int main() {
  scanf("%d %d", &h, &w);
  for (int i = 1; i <= h; i++)
    for (int j = 1; j <= w; j++) cin >> mp[i][j];
  for (int i = 1; i <= h; i++)
    for (int j = 1; j <= w; j++)
      if (mp[i][j] == '.') {
        memset(dep, -1, sizeof(dep));
        dep[i][j] = 1;
        dfs(i, j);
        break;
      }
  int maxval = -1, maxx = 0, maxy = 0;
  for (int i = 1; i <= h; i++) {
    for (int j = 1; j <= w; j++) {
      if (dep[i][j] > maxval) {
        maxval = dep[i][j];
        maxx = i;
        maxy = j;
      }
    }
  }
  memset(dep, -1, sizeof(dep));
  dep[maxx][maxy] = 1;
  dfs(maxx, maxy);
  maxval = -1;
  for (int i = 1; i <= h; i++)
    for (int j = 1; j <= w; j++) {
      maxval = max(maxval, dep[i][j]);
    }
  printf("%d\n", maxval - 1);
  return 0;
}
