#include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include using namespace std; #define fst first #define scd second #define PB push_back #define MP make_pair #define rep(i,x) for(int i=0;i<(x);++i) #define rep1(i,x) for(int i=1;i<=(x);++i) #define rrep(i,x) for(int i=(x)-1;i>=0;--i) #define rrep1(i,x) for(int i=(x);i>=1;--i) #define int long long #define FOR(i,a,x) for(int i=(a);i<(x);++i) #define all(a) a.begin(),a.end() #define rall(a) a.rbegin(),a.rend() #define omajinai ios::sync_with_stdio(false);cin.tie(0) typedef long long ll; typedef vector vi; typedef pair pii; typedef vector vpii; templateT& max(T&a,T&b){if(a>=b)return a;return b;} templateT& min(T&a,T&b){if(abool chmax(T&a,T b){if(abool chmin(T&a,T b){if(a>b){a=b;return true;}return false;} templateT get(){T a;cin>>a;return a;} templateT rev(T a){reverse(all(a));return a;} templateistream&operator>>(istream&is,vector&vec){rep(i,vec.size())is>>vec[i];return is;} templatevector&sort(vector&a){sort(all(a));return a;} const int inf = 1e9; const ll linf = 3e18; const double eps = 1e-9; bool used[3003][3003]; int dist[3003][3003]; struct data { pii p; int d; data(){} data(pii p, int d):p(p),d(d){} }; int dx[8] = {-1, 0, 1, -1, 1, -1, 0, 1}, dy[8] = {-1, -1, -1, 0, 0, 1, 1, 1}; signed main() { int H, W; cin >> H >> W; memset(dist, -1, sizeof(dist)); rep1(i, H) { rep1(j, W) { char c; scanf("\n%c", &c); dist[i][j] = (c == '#') ? inf : -1; } } queue que; rep(i, H + 2) { rep(j, W + 2) { if (dist[i][j] == -1) { que.push((data){(pii){i, j}, 0}); dist[i][j] = 0; used[i][j] = true; } } } while (que.size()) { data da = que.front(); que.pop(); rep(i, 8) { int ny = da.p.fst + dy[i], nx = da.p.scd + dx[i]; if (ny < 0 || ny >= H + 2 || nx < 0 || nx >= W + 2) continue; if (used[ny][nx]) continue; int nd = da.d + 1; dist[ny][nx] = nd; que.push((data){(pii){ny, nx}, nd}); used[ny][nx] = true; } } int ma = 0; rep(i, H + 2) rep(j, W + 2) chmax(ma, dist[i][j]); cout << ma << endl; }