#include <bits/stdc++.h>
using namespace std;
int main() {
  int h, w;
  cin >> h >> w;
  vector<vector<int>> map(h + 2, vector<int>(w + 2, -2));
  pair<int, int> start;
  for (int i = 0, i_len = (h); i < i_len; ++i)
    for (int j = 0, j_len = (w); j < j_len; ++j) {
      char c;
      cin >> c;
      if (c == '.') map[i + 1][j + 1] = -1;
      start = make_pair(i + 1, j + 1);
    }
  queue<pair<int, int>> q;
  q.push(start);
  map[start.first][start.second] = 0;
  vector<int> di = {-1, 0, 0, 1};
  vector<int> dj = {0, -1, 1, 0};
  int max = 0;
  while (!q.empty()) {
    auto v = q.front();
    q.pop();
    for (int k = 0, k_len = (4); k < k_len; ++k) {
      int ni = v.first + di[k];
      int nj = v.second + dj[k];
      if (map[ni][nj] == -1) {
        q.push(make_pair(ni, nj));
        map[ni][nj] = map[v.first][v.second] + 1;
        if (map[ni][nj] > max) {
          max = map[ni][nj];
          start = make_pair(ni, nj);
        }
      }
    }
  }
  for (int i = 0, i_len = (h + 2); i < i_len; ++i)
    for (int j = 0, j_len = (w + 2); j < j_len; ++j) {
      if (map[i][j] >= 0) map[i][j] = -1;
    }
  q.push(start);
  map[start.first][start.second] = 0;
  while (!q.empty()) {
    auto v = q.front();
    q.pop();
    for (int k = 0, k_len = (4); k < k_len; ++k) {
      int ni = v.first + di[k];
      int nj = v.second + dj[k];
      if (map[ni][nj] == -1) {
        q.push(make_pair(ni, nj));
        map[ni][nj] = map[v.first][v.second] + 1;
        if (map[ni][nj] > max) {
          max = map[ni][nj];
        }
      }
    }
  }
  cout << max << endl;
}
