#include <bits/stdc++.h>
using namespace std;
int n, m, sum = 0, ex, ey;
char map[1010][1010];
int vis[1010][1010];
int d[4][2] = {1, 0, 0, 1, -1, 0, 0, -1};
bool judge(int x, int y) {
  if (x >= 0 && x < m && y >= 0 && y < n && map[x][y] != '#') return true;
  return false;
}
struct node {
  int x, y, step;
} now, nex;
void bfs(int sx, int sy) {
  queue<node> q;
  memset(vis, 0, sizeof(vis));
  vis[sx][sy] = 1;
  now.x = sx;
  now.y = sy;
  now.step = 0;
  sum = 0;
  q.push(now);
  while (!q.empty()) {
    now = q.front();
    q.pop();
    for (int i = 0; i < 4; i++) {
      nex.x = now.x + d[i][0];
      nex.y = now.y + d[i][1];
      if (judge(nex.x, nex.y)) {
        nex.step = now.step + 1;
        if (vis[nex.x][nex.y] == 0) {
          vis[nex.x][nex.y] = 1;
          if (sum < nex.step) {
            sum = nex.step;
            ex = nex.x;
            ey = nex.y;
          }
          q.push(nex);
        }
      }
    }
  }
}
int main() {
  int t, sx, sy;
  scanf("%d%d", &m, &n);
  for (int i = 0; i < m; i++) scanf("%s", &map[i]);
  for (int i = 0; i < m; i++) {
    for (int j = 0; j < n; j++) {
      if (map[i][j] == '.') {
        sx = i;
        sy = j;
        break;
      }
    }
  }
  bfs(sx, sy);
  bfs(ex, ey);
  printf("%d\n", sum);
  return 0;
}
