#include <bits/stdc++.h>
using namespace std;
char maze[23][23];
bool visited[23][23];
int level[23][23];
int dx[] = {0, 0, 1, -1};
int dy[] = {1, -1, 0, 0};
int h, w;
int hx, hy;
int bfs(int fx, int fy) {
  memset(visited, 0, sizeof(visited));
  memset(level, 0, sizeof(level));
  int mx = 0;
  queue<pair<int, int>> q;
  q.push({fx, fy});
  visited[fx][fy] = 1;
  level[fx][fy] = 0;
  while (!q.empty()) {
    int px = q.front().first;
    int py = q.front().second;
    q.pop();
    for (int i = 0; i < 4; i++) {
      int x = px + dx[i];
      int y = py + dy[i];
      if (!visited[x][y] && maze[x][y] == '.' && x >= 0 && y >= 0 && x < h &&
          y < w) {
        level[x][y] = level[px][py] + 1;
        visited[x][y] = 1;
        q.push({x, y});
        if (mx < level[x][y]) {
          mx = level[x][y];
          hx = x;
          hy = y;
        }
      }
    }
  }
  return mx;
}
int main() {
  cin >> h >> w;
  int x, y;
  bool f = 1;
  for (int i = 0; i < h; i++) {
    for (int j = 0; j < w; j++) {
      cin >> maze[i][j];
      if (f && maze[i][j] == '.') {
        f = 0;
        x = i;
        y = j;
      }
    }
  }
  bfs(x, y);
  cout << bfs(hx, hy) << endl;
  return 0;
}
