from collections import deque h, w = map(int, input().split()) S = ["." * (w + 2)] + ["." + input() + "." for _ in range(h)] + ["." * (w + 2)] h += 2 w += 2 queue = deque() dist = [[-1] * w for _ in range(h)] for i in range(h): for j in range(w): if S[i][j] == ".": dist[i][j] = 0 queue.append((i, j)) ans = 0 while queue: i, j = queue.popleft() for di in range(-1, 2): ni = i + di if ni == -1 or ni == h: continue for dj in range(-1, 2): nj = j + dj if nj == -1 or nj == w: continue if dist[ni][nj] != -1: continue dist[ni][nj] = dist[i][j] + 1 ans = dist[ni][nj] queue.append((ni, nj)) print(ans)