#include <bits/stdc++.h>
using namespace std;
using vi = vector<long long>;
using vvi = vector<vi>;
using vvvi = vector<vvi>;
const long long inf = 1001001001001001;
const int INF = 1001001001;
const int mod = 1000000007;
const double pi = 3.14159265358979323846;
template <class T>
bool chmin(T& a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
template <class T>
bool chmax(T& a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
template <class T>
void out(T a) {
  cout << a << endl;
}
template <class T>
void outp(T a) {
  cout << '(' << a.first << ',' << a.second << ')' << endl;
}
template <class T>
void outvp(T v) {
  for (long long i = 0; i < (long long)(v.size()); i++) outp(v[i]);
}
template <class T>
void outv(T v) {
  for (long long i = 0; i < (long long)(v.size()); i++) {
    if (i) cout << ' ';
    cout << v[i];
  }
  cout << endl;
}
template <class T>
void outvv(T v) {
  for (long long i = 0; i < (long long)(v.size()); i++) {
    for (long long j = 0; j < (long long)(v[i].size()); j++) {
      if (j) cout << ' ';
      cout << v[i][j];
    }
    cout << endl;
  }
}
int main() {
  long long n, m;
  long long ma = 0, x, y;
  cin >> n >> m;
  vector<vector<bool>> v(n, vector<bool>(m, false));
  vector<vector<bool>> u(n, vector<bool>(m, false));
  vector<vector<bool>> u2(n, vector<bool>(m, false));
  for (long long i = 0; i < (long long)(n); i++) {
    string c;
    cin >> c;
    for (long long j = 0; j < (long long)(m); j++)
      if (c[j] == '.') v[i][j] = true;
  }
  queue<tuple<long long, long long, long long>> q;
  bool t = false;
  for (long long i = 0; i < (long long)(n); i++) {
    for (long long j = 0; j < (long long)(m); j++) {
      if (v[i][j]) {
        q.push(tuple<long long, long long, long long>(i, j, 0));
        t = true;
        break;
      }
    }
    if (t) break;
  }
  while (!q.empty()) {
    auto p = q.front();
    q.pop();
    long long i = get<0>(p), j = get<1>(p), d = get<2>(p);
    u[i][j] = true;
    if (d > ma) {
      ma = d;
      x = i;
      y = j;
    }
    if (i + 1 < n)
      if (!u[i + 1][j] && v[i + 1][j]) {
        u[i + 1][j] = true;
        q.push(tuple<long long, long long, long long>(i + 1, j, d + 1));
      }
    if (i - 1 >= 0)
      if (!u[i - 1][j] && v[i - 1][j]) {
        u[i - 1][j] = true;
        q.push(tuple<long long, long long, long long>(i - 1, j, d + 1));
      }
    if (j + 1 < m)
      if (!u[i][j + 1] && v[i][j + 1]) {
        u[i][j + 1] = true;
        q.push(tuple<long long, long long, long long>(i, j + 1, d + 1));
      }
    if (j - 1 >= 0)
      if (!u[i][j - 1] && v[i][j - 1]) {
        u[i][j - 1] = true;
        q.push(tuple<long long, long long, long long>(i, j - 1, d + 1));
      }
  }
  q.push(tuple<long long, long long, long long>(x, y, 0));
  while (!q.empty()) {
    auto p = q.front();
    q.pop();
    long long i = get<0>(p), j = get<1>(p), d = get<2>(p);
    u2[i][j] = true;
    chmax(ma, d);
    if (i + 1 < n)
      if (!u2[i + 1][j] && v[i + 1][j]) {
        u2[i + 1][j] = true;
        q.push(tuple<long long, long long, long long>(i + 1, j, d + 1));
      }
    if (i - 1 >= 0)
      if (!u2[i - 1][j] && v[i - 1][j]) {
        u2[i - 1][j] = true;
        q.push(tuple<long long, long long, long long>(i - 1, j, d + 1));
      }
    if (j + 1 < m)
      if (!u2[i][j + 1] && v[i][j + 1]) {
        u2[i][j + 1] = true;
        q.push(tuple<long long, long long, long long>(i, j + 1, d + 1));
      }
    if (j - 1 >= 0)
      if (!u2[i][j - 1] && v[i][j - 1]) {
        u2[i][j - 1] = true;
        q.push(tuple<long long, long long, long long>(i, j - 1, d + 1));
      }
  }
  out(ma);
}
