#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll MOD = 1e9 + 7;
int main() {
  int H, W, si, sj;
  cin >> H >> W;
  vector<string> S(H);
  for (int i = 0; i < H; i++) {
    cin >> S[i];
    for (int j = 0; j < W; j++) {
      if (S[i][j] == '.') {
        si = i;
        sj = j;
      }
    }
  }
  vector<vector<int>> d(H, vector<int>(W, -1));
  queue<vector<int>> q;
  q.push({si, sj, 0});
  d[si][sj] = 0;
  while (!q.empty()) {
    auto p = q.front();
    q.pop();
    int di[4] = {1, 0, -1, 0}, dj[4] = {0, 1, 0, -1};
    for (int i = 0; i < 4; i++) {
      int i0 = p[0] + di[i], j0 = p[1] + dj[i];
      if (i0 < 0 || i0 >= H || j0 < 0 || j0 >= W) continue;
      if (d[i0][j0] > -1 || S[i0][j0] == '#') continue;
      d[i0][j0] = p[2] + 1;
      q.push({i0, j0, p[2] + 1});
    }
  }
  int gi, gj, maxd = -1;
  for (int i = 0; i < H; i++) {
    for (int j = 0; j < W; j++) {
      if (d[i][j] > maxd) {
        maxd = d[i][j];
        gi = i;
        gj = j;
      }
    }
  }
  for (int i = 0; i < H; i++)
    for (int j = 0; j < W; j++) d[i][j] = -1;
  q.push({gi, gj, 0});
  d[gi][gj] = 0;
  while (!q.empty()) {
    auto p = q.front();
    q.pop();
    int di[4] = {1, 0, -1, 0}, dj[4] = {0, 1, 0, -1};
    for (int i = 0; i < 4; i++) {
      int i0 = p[0] + di[i], j0 = p[1] + dj[i];
      if (i0 < 0 || i0 >= H || j0 < 0 || j0 >= W) continue;
      if (d[i0][j0] > -1 || S[i0][j0] == '#') continue;
      d[i0][j0] = p[2] + 1;
      q.push({i0, j0, p[2] + 1});
    }
  }
  maxd = -1;
  for (int i = 0; i < H; i++) {
    for (int j = 0; j < W; j++) {
      maxd = max(maxd, d[i][j]);
    }
  }
  cout << maxd << endl;
}
