import heapq def solve(H, W, M): dmap = [] candidates = [] for h in range(0, H): dmap.append([-1] * W) for w in range(0, W): if M[h][w] == ".": dmap[h][w] = 0 heapq.heappush(candidates, (0, h, w)) elif (h == 0 or h == H - 1 or w == 0 or w == W - 1) and M[h][w] == "#": dmap[h][w] = 1 heapq.heappush(candidates, (1, h, w)) max = 0 while(len(candidates)): can = heapq.heappop(candidates) d = can[0] h = can[1] w = can[2] for (xi, yi) in [(h-1, w-1),(h-1, w), (h-1, w+1), (h , w - 1), (h, w + 1), (h + 1, w - 1), (h + 1, w), (h + 1, w + 1)]: if xi > 0 and yi > 0 and xi < H and yi < W: if dmap[xi][yi] == -1: dmap[xi][yi] = d + 1 max = d + 1 if (d + 1, xi, yi) not in candidates: heapq.heappush(candidates, (d + 1, xi, yi)) return max if __name__ == "__main__": H, W = tuple([int(c) for c in input().split(" ")]) print(solve(H, W, [input() for _ in range(0, H)]))