#include #include #include #include #include #include #include #include #include #include #include #include #include #define repd(i,a,b) for (int i=(int)(a);i<(int)(b);i++) #define rep(i,n) repd(i,0,n) #define all(x) (x).begin(),(x).end() #define mod 1000000007 #define inf 2000000007 #define mp make_pair #define pb push_back typedef long long ll; using namespace std; template inline void output(T a, int p) { if(p) cout << fixed << setprecision(p) << a << "\n"; else cout << a << "\n"; } // end of template int dx[8] = {1, 1, 1, 0, 0, -1, -1, -1}; int dy[8] = {1, 0, -1, 1, -1, 1, 0, -1}; int main() { cin.tie(0); ios::sync_with_stdio(0); // source code int H, W; cin >> H >> W; vector A(H); rep(i, H) cin >> A[i]; vector> B(H + 2, vector(W + 2, -1)); vector> st; rep(i, H + 2){ B[i][0] = 0, st.pb(mp(i, 0)); B[i][W + 1] = 0, st.pb(mp(i, W + 1)); } rep(i, W + 2){ B[0][i] = 0, st.pb(mp(0, i)); B[H + 1][i] = 0, st.pb(mp(H + 1, i)); } rep(i, H) rep(j, W){ if(A[i][j] == '.') B[i + 1][j + 1] = 0, st.pb(mp(i + 1, j + 1)); } int cur = 0; while(!st.empty()){ cur++; vector> tmp; for(auto itr: st) { int y = itr.first, x = itr.second; rep(i, 8){ int ny = y + dy[i], nx = x + dx[i]; if(ny >= 0 && ny < H + 2 && nx >= 0 && nx < W + 2){ if(B[ny][nx] == -1){ B[ny][nx] = cur; tmp.pb(mp(ny, nx)); } } } } st = tmp; } output(cur - 1, 0); return 0; }