//#define _GLIBCXX_DEBUG #include #define rep(i, n) for(int i=0; i; using vs = vector; using vi = vector; using vvi = vector; template using PQ = priority_queue; template using PQG = priority_queue, greater >; const int INF = 100010001; const ll LINF = (ll)INF*INF*10; template inline bool chmax(T1 &a, T2 b) {return a < b && (a = b, true);} template inline bool chmin(T1 &a, T2 b) {return a > b && (a = b, true);} template istream &operator>>(istream &is, pair &p) { return is >> p.first >> p.second;} template ostream &operator<<(ostream &os, const pair &p) { return os << p.first << ' ' << p.second;} const int N = 3010; //head int h, w; string s[N]; int di[] = {1, 0, -1, 1, -1, 1, 0, -1}; int dj[] = {-1, -1, -1, 0, 0, 1, 1, 1}; inline bool able(int i, int j) {return i >= 0 and j >= 0 and i < h and j < w;} queue

q; int dist[N][N]; int ans; int main() { ios::sync_with_stdio(false); cin.tie(0); cin >> h >> w; rep(i, h) cin >> s[i+1]; rep(i, h) s[i+1] = "." + s[i+1] + "."; s[0] = s[h+1] = string(w+2, '.'); h += 2; w += 2; //rep(i, h) cout << s[i] << endl; rep(i, h) fill(dist[i], dist[i]+w, INF); rep(i, h) rep(j, w) { if(s[i][j] == '.') { dist[i][j] = 0; q.emplace(i, j); } } while(!q.empty()) { P now = q.front(); q.pop(); int ni = now.first, nj = now.second; rep(i, 8) { int mi = ni+di[i]; int mj = nj+dj[i]; if(able(mi, mj) and dist[mi][mj] == INF) { dist[mi][mj] = dist[ni][nj]+1; q.emplace(mi, mj); } } } rep(i, h) rep(j, w) chmax(ans, dist[i][j]); cout << ans << endl; }