#define _USE_MATH_DEFINES #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include using namespace std; typedef long long ll; typedef unsigned long long ull; typedef pair i_i; typedef pair ll_i; typedef pair d_i; typedef pair ll_ll; typedef pair d_d; struct edge { int u, v; ll w; }; int INF = INT_MAX / 2; ll MOD = 1000000007; ll _MOD = 1000000009; double EPS = 1e-10; char c[3010]; int main() { int H, W; cin >> H >> W; vector a(H); for (int y = 0; y < H; y++) { scanf("%s", c); a[y] = c; } queue q; for (int y = 0; y < H; y++) for (int x = 0; x < W; x++) if (a[y][x] == '.') q.push(i_i(y, x)); int t; for (t = 0; !q.empty(); t++) { queue _q; while (!q.empty()) { i_i yx = q.front(); q.pop(); int y = yx.first, x = yx.second; for (int dy = -1; dy <= 1; dy++) for (int dx = -1; dx <= 1; dx++) { int _y = y + dy, _x = x + dx; if (0 <= _y && _y < H && 0 <= _x && _x < W && a[_y][_x] == '#') { a[_y][_x] = '.'; _q.push(i_i(_y, _x)); } } } q = _q; } cout << t - 1 << endl; }