#include <bits/stdc++.h>
using namespace std;
int64_t INF = 1e18;
int64_t mod = 1e9 + 7;
typedef struct {
  int64_t y, x;
} p_t;
int main() {
  int64_t h, w;
  bool f[21][21] = {};
  cin >> h >> w;
  for (int64_t i = 0; i < h; i++) {
    for (int64_t j = 0; j < w; j++) {
      char a;
      cin >> a;
      f[i][j] = (a == '.');
    }
  }
  int64_t d[21][21] = {};
  for (int64_t i = 0; i < h; i++) {
    for (int64_t j = 0; j < w; j++) {
      d[i][j] = INF;
    }
  }
  p_t p = {0, 0};
  for (int64_t i = 0; i < h; i++) {
    for (int64_t j = 0; j < w; j++) {
      if (f[i][j]) {
        p = {i, j};
        i = j = 30;
      }
    }
  }
  queue<p_t> q;
  q.push(p);
  d[p.y][p.x] = 0;
  while (not q.empty()) {
    p_t cur = q.front();
    q.pop();
    int64_t dx[] = {-1, 0, 1, 0};
    int64_t dy[] = {0, 1, 0, -1};
    for (int64_t i = 0; i < 4; i++) {
      int64_t nx = dx[i] + cur.x;
      int64_t ny = dy[i] + cur.y;
      if (nx < 0 or w <= nx or ny < 0 or h <= ny) continue;
      if (f[ny][nx] and d[ny][nx] > d[cur.y][cur.x] + 1) {
        d[ny][nx] = d[cur.y][cur.x] + 1;
        q.push({ny, nx});
      }
    }
  }
  int64_t ma = -1;
  p_t indice;
  for (int64_t i = 0; i < h; i++) {
    for (int64_t j = 0; j < w; j++) {
      if (d[i][j] != INF and ma < d[i][j]) {
        ma = d[i][j];
        indice = {i, j};
      }
    }
  }
  for (int64_t i = 0; i < h; i++) {
    for (int64_t j = 0; j < w; j++) {
      d[i][j] = INF;
    }
  }
  q.push(indice);
  d[indice.y][indice.x] = 0;
  while (not q.empty()) {
    p_t cur = q.front();
    q.pop();
    int64_t dx[] = {-1, 0, 1, 0};
    int64_t dy[] = {0, 1, 0, -1};
    for (int64_t i = 0; i < 4; i++) {
      int64_t nx = dx[i] + cur.x;
      int64_t ny = dy[i] + cur.y;
      if (nx < 0 or w <= nx or ny < 0 or h <= ny) continue;
      if (f[ny][nx] and d[ny][nx] > d[cur.y][cur.x] + 1) {
        d[ny][nx] = d[cur.y][cur.x] + 1;
        q.push({ny, nx});
      }
    }
  }
  ma = -1;
  for (int64_t i = 0; i < h; i++) {
    for (int64_t j = 0; j < w; j++) {
      if (d[i][j] != INF and d[i][j] > ma) {
        ma = d[i][j];
      }
    }
  }
  cout << (ma) << '\n';
  return 0;
}
