#include <bits/stdc++.h>
int h, w;
bool S[20][20];
int v[20][20];
int enc(int a, int b) { return (b << 16) | a; }
int main() {
  scanf("%d%d", &h, &w);
  for (int i = 0; i < h; i++) {
    for (int j = 0; j < w; j++) {
      char c;
      do {
        scanf("%c", &c);
      } while (c != '#' && c != '.');
      S[i][j] = c == '.';
      v[i][j] = -1;
    }
  }
  std::queue<int> q;
  q.push(0);
  v[0][0] = 0;
  while (!q.empty()) {
    int z = q.front();
    q.pop();
    int a = z % (1 << 16);
    int b = z >> 16;
    if (a && S[a - 1][b] && v[a - 1][b] == -1)
      q.push(enc(a - 1, b)), v[a - 1][b] = v[a][b] + 1;
    if (a < h && S[a + 1][b] && v[a + 1][b] == -1)
      q.push(enc(a + 1, b)), v[a + 1][b] = v[a][b] + 1;
    if (b && S[a][b - 1] && v[a][b - 1] == -1)
      q.push(enc(a, b - 1)), v[a][b - 1] = v[a][b] + 1;
    if (b < w && S[a][b + 1] && v[a][b + 1] == -1)
      q.push(enc(a, b + 1)), v[a][b + 1] = v[a][b] + 1;
  }
  int ml = 0;
  int aa, bb;
  for (int i = 0; i < h; i++) {
    for (int j = 0; j < w; j++) {
      if (v[i][j] > ml) {
        ml = v[i][j];
        aa = i;
        bb = j;
      }
      v[i][j] = -1;
    }
  }
  q.push(enc(aa, bb));
  v[aa][bb] = 0;
  while (!q.empty()) {
    int z = q.front();
    q.pop();
    int a = z % (1 << 16);
    int b = z >> 16;
    if (a && S[a - 1][b] && v[a - 1][b] == -1)
      q.push(enc(a - 1, b)), v[a - 1][b] = v[a][b] + 1;
    if (a < h && S[a + 1][b] && v[a + 1][b] == -1)
      q.push(enc(a + 1, b)), v[a + 1][b] = v[a][b] + 1;
    if (b && S[a][b - 1] && v[a][b - 1] == -1)
      q.push(enc(a, b - 1)), v[a][b - 1] = v[a][b] + 1;
    if (b < w && S[a][b + 1] && v[a][b + 1] == -1)
      q.push(enc(a, b + 1)), v[a][b + 1] = v[a][b] + 1;
  }
  ml = 0;
  for (int i = 0; i < h; i++) {
    for (int j = 0; j < w; j++) {
      if (v[i][j] > ml) {
        ml = v[i][j];
        aa = i;
        bb = j;
      }
      v[i][j] = -1;
    }
  }
  printf("%d\n", ml);
  return 0;
}
