#include using namespace std; using i64 = int64_t; using vi = vector; using vvi = vector; int main() { ios::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); int h, w; cin >> h >> w; vvi b(h + 2, vi(w + 2)); for (int i = 1; i < h + 1; i++) { for (int j = 1; j < w + 1; j++) { b[i][j] = 1e9; } } using ii = pair; queue que; for (int i = 0; i < h; i++) { for (int j = 0; j < w; j++) { char c; cin >> c; if (c == '.') { b[i + 1][j + 1] = 0; } } } for (int i = 0; i < h + 2; i++) { for (int j = 0; j < w + 2; j++) { if (b[i][j] == 0) { que.push(ii(i, j)); } } } int dx[] = {1, 1, 1, 0, -1, -1, -1, 0}; int dy[] = {1, 0, -1, -1, -1, 0, 1, 1}; auto ok = [&](int x, int y) { return 0 <= x && x < h + 2 && 0 <= y && y < w + 2; }; while (que.size()) { ii t = que.front(); que.pop(); for (int i = 0; i < 8; i++) { int x = t.first + dx[i]; int y = t.second + dy[i]; if (ok(x, y) && b[t.first][t.second] + 1 < b[x][y]) { b[x][y] = b[t.first][t.second] + 1; que.push(ii(x, y)); } } } i64 nax = -1; for (int i = 0; i < h + 2; i++) { for (int j = 0; j < w + 2; j++) { nax = max(nax, b[i][j]); } } cout << nax << endl; }