#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int, int>;
int main() {
  int h, w;
  cin >> h >> w;
  vector<vector<bool>> ss(h, vector<bool>(w));
  int si = -1, sj = -1;
  for (int i = 0; i < (int)(h); i++)
    for (int j = 0; j < (int)(w); j++) {
      char c;
      cin >> c;
      if (c == '.') {
        ss[i][j] = true;
      } else {
        ss[i][j] = false;
      }
      if (ss[i][j] && si == -1 && sj == -1) {
        si = i;
        sj = j;
      }
    }
  queue<P> que;
  vector<vector<int>> dist(h, vector<int>(w, -1));
  que.push(P(si, sj));
  dist[si][sj] = 0;
  while (!que.empty()) {
    auto p = que.front();
    int i = p.first;
    int j = p.second;
    que.pop();
    if (0 <= i - 1 && ss[i - 1][j] && dist[i - 1][j] == -1) {
      dist[i - 1][j] = dist[i][j] + 1;
      que.push(P(i - 1, j));
    }
    if (i + 1 < h && ss[i + 1][j] && dist[i + 1][j] == -1) {
      dist[i + 1][j] = dist[i][j] + 1;
      que.push(P(i + 1, j));
    }
    if (0 <= j - 1 && ss[i][j - 1] && dist[i][j - 1] == -1) {
      dist[i][j - 1] = dist[i][j] + 1;
      que.push(P(i, j - 1));
    }
    if (j + 1 < w && ss[i][j + 1] && dist[i][j + 1] == -1) {
      dist[i][j + 1] = dist[i][j] + 1;
      que.push(P(i, j + 1));
    }
  }
  int m = 0;
  for (int i = 0; i < (int)(h); i++)
    for (int j = 0; j < (int)(w); j++) {
      if (m < dist[i][j]) {
        si = i;
        sj = j;
        m = dist[i][j];
      }
    }
  que.push(P(si, sj));
  dist.assign(h, vector<int>(w, -1));
  dist[si][sj] = 0;
  while (!que.empty()) {
    auto p = que.front();
    int i = p.first;
    int j = p.second;
    que.pop();
    if (0 <= i - 1 && ss[i - 1][j] && dist[i - 1][j] == -1) {
      dist[i - 1][j] = dist[i][j] + 1;
      que.push(P(i - 1, j));
    }
    if (i + 1 < h && ss[i + 1][j] && dist[i + 1][j] == -1) {
      dist[i + 1][j] = dist[i][j] + 1;
      que.push(P(i + 1, j));
    }
    if (0 <= j - 1 && ss[i][j - 1] && dist[i][j - 1] == -1) {
      dist[i][j - 1] = dist[i][j] + 1;
      que.push(P(i, j - 1));
    }
    if (j + 1 < w && ss[i][j + 1] && dist[i][j + 1] == -1) {
      dist[i][j + 1] = dist[i][j] + 1;
      que.push(P(i, j + 1));
    }
  }
  m = 0;
  for (int i = 0; i < (int)(h); i++)
    for (int j = 0; j < (int)(w); j++) {
      if (m < dist[i][j]) {
        si = i;
        sj = j;
        m = dist[i][j];
      }
    }
  cout << m << endl;
  return 0;
}
