#include <bits/stdc++.h>
using namespace std;
int h, w;
int dis[2][25][25];
char maze[25][25];
int dir[][2] = {0, 1, 0, -1, 1, 0, -1, 0};
int sx[2], sy[2];
int d;
queue<pair<int, int> > q;
bool val(int x, int y) {
  if (~x && x < h && ~y && y < w && maze[x][y] != '#') return 1;
  return 0;
}
void bfs(int id) {
  while (!q.empty()) {
    pair<int, int> a = q.front();
    int x = a.first;
    int y = a.second;
    q.pop();
    if (d < dis[id][x][y]) {
      d = dis[id][x][y];
      sx[id] = x;
      sy[id] = y;
    }
    for (int i = 0; i < 4; i++) {
      int nx = x + dir[i][0];
      int ny = y + dir[i][1];
      if (!dis[id][nx][ny] && val(nx, ny)) {
        q.push({nx, ny});
        dis[id][nx][ny] = dis[id][x][y] + 1;
      }
    }
  }
}
int main() {
  cin >> h >> w;
  for (int i = 0; i < h; i++) {
    getchar();
    for (int j = 0; j < w; j++) {
      maze[i][j] = getchar();
    }
  }
  while (!q.empty()) q.pop();
  bool flag = 0;
  for (int i = 0; i < h; i++) {
    for (int j = 0; j < w; j++) {
      if (maze[i][j] == '.') {
        dis[0][i][j] = 1;
        q.push({i, j});
        flag = 1;
        break;
      }
    }
    if (flag) break;
  }
  d = -1;
  bfs(0);
  while (!q.empty()) q.pop();
  q.push({sx[0], sy[0]});
  dis[1][sx[0]][sy[0]] = 1;
  d = -1;
  bfs(1);
  cout << d - 1 << endl;
  return 0;
}
