#include "bits/stdc++.h" using namespace std; #define rep(i,n) for(int (i)=0;(i)<(int)(n);++(i)) #define rer(i,l,u) for(int (i)=(int)(l);(i)<=(int)(u);++(i)) #define reu(i,l,u) for(int (i)=(int)(l);(i)<(int)(u);++(i)) static const int INF = 0x3f3f3f3f; static const long long INFL = 0x3f3f3f3f3f3f3f3fLL; typedef vector vi; typedef pair pii; typedef vector > vpii; typedef long long ll; template static void amin(T &x, U y) { if(y < x) x = y; } template static void amax(T &x, U y) { if(x < y) x = y; } int main() { int H; int W; while(~scanf("%d%d", &H, &W)) { H += 2, W += 2; vector S(H); rep(i, H - 2) { cin >> S[i + 1]; S[i + 1] = '.' + S[i + 1] + '.'; } S[0] = S[H - 1] = string(W, '.'); vector> vis(H, vector(W)); vector q, nq; rep(i, H) rep(j, W) if(S[i][j] == '.') { nq.emplace_back(i, j); vis[i][j] = true; } int dist = 0, ans = 0; while(!nq.empty()) { q.swap(nq); while(!q.empty()) { int i, j; tie(i, j) = q.back(); q.pop_back(); amax(ans, dist); rer(dy, -1, 1) rer(dx, -1, 1) if(dy || dx) { int yy = i + dy, xx = j + dx; if(yy < 0 || yy >= H || xx < 0 || xx >= W) continue; if(!vis[yy][xx]) { vis[yy][xx] = true; nq.emplace_back(yy, xx); } } } ++ dist; } printf("%d\n", ans); } return 0; }