#include using namespace std; #define int long long const int INF = LLONG_MAX/2; const int dx[] = {1, 1, 1, 0, -1, -1, -1, 0}, dy[] = {-1, 0, 1, 1, 1, 0, -1, -1}; int H, W; char fld[3002][3002]; bool isUsed[3002][3002]; signed main() { fill(fld[0], fld[0] + 3002*3002, '.'); cin >> H >> W; queue< pair< pair, int> > q; for (int i = 1; i < H + 1; i++) { for (int j = 1; j < W + 1; j++) { cin >> fld[i][j]; } } for (int i = 0; i < H + 2; i++) { for (int j = 0; j < W + 2; j++) { if (fld[i][j] == '.') q.emplace(make_pair(make_pair(j, i), 0)); } } int ma = 0; while (!q.empty()) { pair p = q.front().first; int cost = q.front().second; q.pop(); isUsed[p.second][p.first] = true; ma = cost; for (int i = 0; i < 8; i++) { int nx = p.first + dx[i], ny = p.second + dy[i]; if (nx < 0 || W + 2 <= nx || ny < 0 || H + 2 <= ny || isUsed[ny][nx]) continue; isUsed[ny][nx] = true; q.emplace(make_pair(make_pair(nx, ny), cost + 1)); } } printf("%lld\n", ma); return 0; }