#include <bits/stdc++.h>
using namespace std;
using ll = long long;
template <class T>
inline bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T>
inline bool chmin(T &a, T b) {
  if (b < a) {
    a = b;
    return 1;
  }
  return 0;
}
int main() {
  int h, w;
  cin >> h >> w;
  vector<string> field(h);
  for (int i = 0; i < (int)(h); i++) cin >> field[i];
  const int dy[4] = {1, 0, -1, 0};
  const int dx[4] = {0, 1, 0, -1};
  int sy, sx;
  bool ok = false;
  for (int y = 0; y < (int)(h); y++) {
    for (int x = 0; x < (int)(w); x++) {
      if (field[y][x] == '.') {
        sy = y;
        sx = x;
        ok = true;
        break;
      }
    }
    if (ok) break;
  }
  queue<int> qy, qx;
  vector<vector<int>> dist(h, vector<int>(w, -1));
  qy.push(sy);
  qx.push(sx);
  dist[sy][sx] = 0;
  while (!qy.empty()) {
    int y = qy.front(), x = qx.front();
    qy.pop();
    qx.pop();
    for (int i = 0; i < 4; ++i) {
      int ny = y + dy[i], nx = x + dx[i];
      if (ny < 0 || h <= ny || nx < 0 || w <= nx) continue;
      if (dist[ny][nx] >= 0) continue;
      if (field[ny][nx] == '#') continue;
      qy.push(ny);
      qx.push(nx);
      dist[ny][nx] = dist[y][x] + 1;
    }
  }
  int mx = 0;
  for (int y = 0; y < (int)(h); y++) {
    for (int x = 0; x < (int)(w); x++) {
      if (chmax(mx, dist[y][x])) {
        sy = y;
        sx = x;
      }
    }
  }
  dist = vector<vector<int>>(h, vector<int>(w, -1));
  qy.push(sy);
  qx.push(sx);
  dist[sy][sx] = 0;
  while (!qy.empty()) {
    int y = qy.front(), x = qx.front();
    qy.pop();
    qx.pop();
    for (int i = 0; i < 4; ++i) {
      int ny = y + dy[i], nx = x + dx[i];
      if (ny < 0 || h <= ny || nx < 0 || w <= nx) continue;
      if (dist[ny][nx] >= 0) continue;
      if (field[ny][nx] == '#') continue;
      qy.push(ny);
      qx.push(nx);
      dist[ny][nx] = dist[y][x] + 1;
    }
  }
  mx = 0;
  for (int y = 0; y < (int)(h); y++) {
    for (int x = 0; x < (int)(w); x++) {
      chmax(mx, dist[y][x]);
    }
  }
  cout << mx << endl;
}
