#include <bits/stdc++.h>
using namespace std;
bool used[1001][1001];
int dist[1001][1001];
int n, m, r, w, wans;
const int dx[] = {0, 0, -1, 1}, dy[] = {1, -1, 0, 0};
string s[1001];
void DFS(int ro, int col, int ret) {
  used[ro][col] = true;
  dist[ro][col] = ret;
  ret++;
  for (int i = 0; i < 4; i++) {
    int nr = ro + dx[i], nc = col + dy[i];
    if (nr < 0 || nc < 0 || nr >= n || nc >= m || s[nr][nc] == '#' ||
        (ret > dist[nr][nc] && dist[nr][nc] >= 0))
      continue;
    DFS(nr, nc, ret);
  }
}
int main() {
  cin >> n >> m;
  for (int i = 0; i < n; i++) {
    cin >> s[i];
    for (int j = 0; j < m; j++) {
      dist[i][j] = -1;
      if (s[i][j] == '.') {
        r = i;
        w = j;
      }
    }
  }
  DFS(r, w, 0);
  pair<int, pair<int, int> > piii;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      if (dist[i][j] > piii.first)
        piii = make_pair(dist[i][j], make_pair(i, j));
      dist[i][j] = -1;
      used[i][j] = false;
    }
  }
  DFS(piii.second.first, piii.second.second, 0);
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      wans = max(wans, dist[i][j]);
    }
  }
  cout << wans << endl;
  return 0;
}
