#include <cstdio>
#include <queue>
#include <cstring>
#include <algorithm>

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;
      }
    }
  }

  int res = 0;
  for (int i = 0; i < h; i++) {
    for (int j = 0; j < w; j++) {
      if (g[i][j] == '.') {
	res = max(res, *max_element(solve(i*100+j), c+2222));
      }
    }
  }
  printf("%d\n", res);
  return 0;
}
