#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using Pi = pair<int, int>;
using Pl = pair<ll, ll>;
using Vl = vector<ll>;
using vi = vector<int>;
using Graph = vector<vi>;
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int H, W;
  cin >> H >> W;
  vector<vector<char>> maze(H, vector<char>(W, '.'));
  vector<vi> dist1(H, vi(W, -1));
  vector<vi> dist2(H, vi(W, -1));
  for (long long i = 0; i < (long long)H; i++)
    for (long long j = 0; j < (long long)W; j++) cin >> maze.at(i).at(j);
  queue<Pi> que;
  bool break_flag = false;
  for (long long i = 0; i < (long long)H; i++) {
    for (long long j = 0; j < (long long)W; j++) {
      if (maze.at(i).at(j) == '.') {
        que.emplace(make_pair(i, j));
        dist1.at(i).at(j) = 0;
        break_flag = true;
        break;
      }
    }
    if (break_flag) break;
  }
  int w[4] = {1, 0, 0, -1};
  int h[4] = {0, 1, -1, 0};
  while (!que.empty()) {
    Pi now = que.front();
    que.pop();
    for (long long i = 0; i < (long long)4; i++) {
      int nh = now.first + h[i];
      int nw = now.second + w[i];
      if (nh < 0 || nh >= H || nw < 0 || nw >= W) continue;
      if (maze.at(nh).at(nw) == '#') continue;
      if (dist1.at(nh).at(nw) != -1) continue;
      dist1.at(nh).at(nw) = dist1.at(now.first).at(now.second) + 1;
      que.emplace(make_pair(nh, nw));
    }
  }
  int max_dist = -1;
  Pi max_pair;
  for (long long i = 0; i < (long long)H; i++) {
    for (long long j = 0; j < (long long)W; j++) {
      if (dist1.at(i).at(j) > max_dist) {
        max_dist = dist1.at(i).at(j);
        max_pair = make_pair(i, j);
      }
    }
  }
  que.emplace(max_pair);
  dist2.at(max_pair.first).at(max_pair.second) = 0;
  while (!que.empty()) {
    Pi now = que.front();
    que.pop();
    for (long long i = 0; i < (long long)4; i++) {
      int nh = now.first + h[i];
      int nw = now.second + w[i];
      if (nh < 0 || nh >= H || nw < 0 || nw >= W) continue;
      if (maze.at(nh).at(nw) == '#') continue;
      if (dist2.at(nh).at(nw) != -1) continue;
      dist2.at(nh).at(nw) = dist2.at(now.first).at(now.second) + 1;
      que.emplace(make_pair(nh, nw));
    }
  }
  for (long long i = 0; i < (long long)H; i++) {
    for (long long j = 0; j < (long long)W; j++) {
      if (dist2.at(i).at(j) > max_dist) {
        max_dist = dist2.at(i).at(j);
      }
    }
  }
  cout << max_dist << endl;
}
