#include <bits/stdc++.h>
using namespace std;
int h, w;
int c[2222];
char g[22][22];
int* solve(int p) {
  queue<int> q;
  q.push(p);
  memset(c, -1, sizeof(c));
  c[p] = 0;
  int dx[] = {0, 1, 0, -1};
  int dy[] = {1, 0, -1, 0};
  while (!q.empty()) {
    p = q.front();
    q.pop();
    for (int i = 0; i < 4; i++) {
      int x = p % 100 + dx[i], y = p / 100 + dy[i];
      if (x >= 0 && x < w && y >= 0 && y < h && g[y][x] == '.' &&
          c[y * 100 + x] < 0) {
        c[y * 100 + x] = c[p] + 1;
        q.push(y * 100 + x);
      }
    }
  }
  return c;
}
int main(void) {
  scanf("%d%d", &h, &w);
  int x, y;
  for (int i = 0; i < h; i++) {
    for (int j = 0; j < w; j++) {
      scanf(" %c", g[i] + j);
      if (g[i][j] == '.') {
        x = j;
        y = i;
      }
    }
  }
  solve(y * 100 + x);
  solve(max_element(c, c + 2222) - c);
  printf("%d\n", *max_element(solve(max_element(c, c + 2222) - c), c + 2222));
  return 0;
}
