#include <bits/stdc++.h>
using namespace std;
long long int MOD = 1000000000 + 7;
using ll = long long;
ll C(ll n, ll k) {
  if (n < k) {
    return 0;
  }
  if (n / 2 < k) {
    k = n - k;
  }
  ll num = 1;
  ll den = 1;
  for (ll i = 0; i < k; ++i) {
    num *= (n - i);
    den *= (i + 1);
    num %= MOD;
    den %= MOD;
  }
  return num / den;
}
struct Mat {
  ll h_ = 0;
  ll w_ = 0;
  vector<ll> x;
  void make(ll h, ll w, ll i = -1) {
    h_ = h;
    w_ = w;
    x.resize(w * h, i);
  }
  ll& set(ll i, ll j) { return x[i * w_ + j]; }
  ll get(ll i, ll j) const {
    if (i < 0) {
      return 9999;
    }
    if (j < 0) {
      return 9999;
    }
    if (h_ <= i) {
      return 9999;
    }
    if (w_ <= j) {
      return 9999;
    }
    return x[i * w_ + j];
  }
  void pr() const {}
};
bool is_finished(const Mat& m) {
  for (ll i = 0; i < m.h_; ++i) {
    for (ll j = 0; j < m.w_; ++j) {
      if (m.get(i, j) == 9999) {
        return false;
      }
    }
  }
  return true;
}
void solve(Mat m, Mat& mm) {
  ll h = m.h_;
  ll w = m.w_;
  while (!is_finished(mm)) {
    for (ll i = 0; i < h; ++i) {
      for (ll j = 0; j < w; ++j) {
        if (m.get(i, j) == 1) {
          mm.set(i, j) = 999;
          continue;
        }
        ll u = mm.get(i - 1, j);
        ll d = mm.get(i + 1, j);
        ll l = mm.get(i, j - 1);
        ll r = mm.get(i, j + 1);
        u = u < 0 ? 9999 : u;
        d = d < 0 ? 9999 : d;
        l = l < 0 ? 9999 : l;
        r = r < 0 ? 9999 : r;
        ll dist = u < d ? u : d;
        dist = dist < l ? dist : l;
        dist = dist < r ? dist : r;
        if (dist >= 999) {
          continue;
        }
        if (mm.get(i, j) < dist) {
          continue;
        }
        mm.set(i, j) = dist + 1;
      }
    }
    mm.pr();
  }
}
int main() {
  ll h, w;
  cin >> h >> w;
  Mat m;
  Mat mm;
  Mat mmm;
  m.make(h, w);
  mm.make(h, w, 9999);
  mmm.make(h, w, 9999);
  for (ll i = 0; i < h; ++i) {
    string a;
    cin >> a;
    for (ll j = 0; j < w; ++j) {
      if (a[j] == '#') {
        m.set(i, j) = 1;
      } else {
        m.set(i, j) = 0;
      }
    }
  }
  ll si = -1;
  ll sj = -1;
  for (ll i = 0; i < h; ++i) {
    for (ll j = 0; j < w; ++j) {
      if (m.get(i, j) == 0) {
        si = i;
        sj = j;
      }
    }
  }
  mm.set(si, sj) = 0;
  solve(m, mm);
  si = -1;
  sj = -1;
  ll emax = -1;
  for (ll i = 0; i < h; ++i) {
    for (ll j = 0; j < w; ++j) {
      if (mm.get(i, j) == 999) {
        continue;
      }
      if (m.get(i, j) < 0) {
        continue;
      }
      if (emax < mm.get(i, j)) {
        emax = mm.get(i, j);
        si = i;
        sj = j;
      }
    }
  }
  mmm.set(si, sj) = 0;
  mmm.pr();
  solve(m, mmm);
  si = -1;
  sj = -1;
  emax = -1;
  for (ll i = 0; i < h; ++i) {
    for (ll j = 0; j < w; ++j) {
      if (mmm.get(i, j) == 999) {
        continue;
      }
      if (m.get(i, j) < 0) {
        continue;
      }
      if (emax < mmm.get(i, j)) {
        emax = mmm.get(i, j);
      }
    }
  }
  cout << emax << endl;
}
