import sys input = sys.stdin.readline H, W = map(int, input().split()) S = [] S.append(["."] * (W + 2)) for i in range(H): S.append(["."] + list(input().rstrip()) + ["."]) S.append(["."] * (W + 2)) 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 i in range(H + 2): for j in range(W + 2): if S[i][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)