import sys input = sys.stdin.readline H, W = map(int, input().split()) dx = [1, 0, -1, 0, 1, 1, -1, -1] dy = [0, 1, 0, -1, 1, -1, 1, -1] from collections import * Q = deque() dist = [[-1] * (W + 2) for i in range(H + 2)] for j in range(W + 2): dist[0][j] = 0 Q.append((0, j)) dist[H+1][j] = 0 Q.append((H+1, j)) for i in range(1, H+1): L = ["."] + list(input().rstrip()) + ["."] for j in range(W + 2): if L[j] == ".": dist[i][j] = 0 Q.append((i, j)) ans = 0 while Q: i, j = Q.popleft() for k in range(8): x = i + dx[k] y = j + dy[k] if x < 0 or x > H + 1 or y < 0 or y > W + 1: continue if dist[x][y] != -1: continue dist[x][y] = dist[i][j] + 1 ans = max(ans, dist[x][y]) Q.append((x, y)) print(ans)