#include <bits/stdc++.h>
using namespace std;
int h, w, tmp, res = -1, f = 0, a, b, posa, posb;
int cost[25][25];
char c[24][24];
queue<pair<int, int> > q;
int dx[] = {0, 1, 0, -1, 0};
int dy[] = {0, 0, 1, 0, -1};
void bfs(int X1, int Y1) {
  q.push(make_pair(X1, Y1));
  cost[X1][Y1] = 0;
  while (!q.empty()) {
    int x = q.front().first, y = q.front().second;
    q.pop();
    for (int i = 1; i <= 4; i++) {
      int fx = x + dx[i], fy = y + dy[i];
      if (fx >= 1 && fx <= h && fy >= 1 && fy <= w && c[fx][fy] != '#') {
        if (cost[fx][fy] == -1) {
          cost[fx][fy] = cost[x][y] + 1;
          q.push(make_pair(fx, fy));
        }
      }
    }
  }
}
int main() {
  cin >> h >> w;
  for (int i = 1; i <= h; i++) {
    for (int j = 1; j <= w; j++) {
      cin >> c[i][j];
      if (c[i][j] != '#' && f == 0) {
        a = i;
        b = j;
        f = 1;
      }
    }
  }
  memset(cost, -1, sizeof(cost));
  bfs(a, b);
  for (int i = 1; i <= h; i++) {
    for (int j = 1; j <= w; j++) {
      if (tmp < cost[i][j]) {
        tmp = cost[i][j];
        posa = i;
        posb = j;
      }
    }
  }
  memset(cost, -1, sizeof(cost));
  bfs(posa, posb);
  for (int i = 1; i <= h; i++) {
    for (int j = 1; j <= w; j++) {
      res = max(res, cost[i][j]);
    }
  }
  cout << res;
}
