#include #include #include #define rep(i, l, r) for (int i = (l); i <= (r); i ++ ) #define per(i, r, l) for (int i = (r); i >= (l); i -- ) using namespace std; const int N = 3005, dx[] = {0, 0, 1, -1}, dy[] = {1, -1, 0, 0}; int n, m; string ch[N]; bool st[N][N]; queue > q1, q2; int main() { ios::sync_with_stdio(0), cin.tie(0), cout.tie(0); cin >> n >> m; rep(i, 1, n) { cin >> ch[i]; ch[i] = '.' + ch[i] + '.'; } rep(i, 0, m + 1) ch[0] += '.', ch[n + 1] += '.'; rep(i, 0, n + 1) rep(j, 0, m + 1) if (ch[i][j] == '.') { q1.push({i, j}); st[i][j] = 1; } int now = 0, ans = 0; while (!q1.empty()) { swap(q1, q2); while (!q2.empty()) { auto t = q2.front(); q2.pop(); rep(dx, -1, 1) rep(dy, -1, 1) if (dx != 0 || dy != 0) { int nx = t.first + dx, ny = t.second + dy; ans = max(ans, now); if (nx < 0 || ny < 0 || nx > n + 1 || ny > m + 1) continue; if (!st[nx][ny]) { st[nx][ny] = 1; q1.push({nx, ny}); } } } now += 1; } printf("%d\n", ans); return 0; }