#include <bits/stdc++.h>
using namespace std;
const int inf = 1e9;
const long long int mod = 1e9 + 7;
int dx[] = {1, 0, -1, 0};
int dy[] = {0, 1, 0, -1};
int main() {
  int h, w;
  cin >> h >> w;
  vector<vector<char>> s(h + 2, vector<char>(w + 2, '#'));
  int si, sj;
  for (int i = 1; i <= h; i++) {
    for (int j = 1; j <= w; j++) {
      cin >> s[i][j];
      if (s[i][j] == '.') {
        si = i;
        sj = j;
      }
    }
  }
  vector<vector<int>> mincost(h + 2, vector<int>(w + 2, inf));
  queue<pair<int, int>> wait;
  wait.push(pair<int, int>(si, sj));
  mincost[si][sj] = 0;
  while (!wait.empty()) {
    pair<int, int> curr = wait.front();
    wait.pop();
    int ci = curr.first, cj = curr.second;
    for (int d = 0; d < 4; d++) {
      int ni = ci + dx[d], nj = cj + dy[d];
      if (s[ni][nj] == '.' and mincost[ni][nj] == inf) {
        mincost[ni][nj] = mincost[ci][cj] + 1;
        wait.push(pair<int, int>(ni, nj));
      }
    }
  }
  int maxcost = -1;
  for (int i = 1; i <= h; i++) {
    for (int j = 1; j <= w; j++) {
      if (mincost[i][j] != inf and mincost[i][j] > maxcost) {
        maxcost = mincost[i][j];
        si = i;
        sj = j;
      }
    }
  }
  mincost = vector<vector<int>>(h + 2, vector<int>(w + 2, inf));
  mincost[si][sj] = 0;
  wait.push(pair<int, int>(si, sj));
  while (!wait.empty()) {
    pair<int, int> curr = wait.front();
    wait.pop();
    int ci = curr.first, cj = curr.second;
    for (int d = 0; d < 4; d++) {
      int ni = ci + dx[d], nj = cj + dy[d];
      if (s[ni][nj] == '.' and mincost[ni][nj] == inf) {
        mincost[ni][nj] = mincost[ci][cj] + 1;
        wait.push(pair<int, int>(ni, nj));
      }
    }
  }
  maxcost = -1;
  for (int i = 1; i <= h; i++) {
    for (int j = 1; j <= w; j++) {
      if (mincost[i][j] != inf and mincost[i][j] > maxcost) {
        maxcost = mincost[i][j];
        si = i;
        sj = j;
      }
    }
  }
  cout << maxcost << endl;
  return 0;
}
