import os



import itertools

import sys



if os.getenv("LOCAL"):

    sys.stdin = open("_in.txt", "r")



sys.setrecursionlimit(2147483647)

INF = float("inf")

IINF = 10 ** 18

MOD = 10 ** 9 + 7



H, W = list(map(int, sys.stdin.readline().split()))

A = [list(sys.stdin.readline().rstrip()) for _ in range(H)]





def ok(h, w):

    return 0 <= h < H and 0 <= w < W and A[h][w] == '.'





nexts = []

for h, w in itertools.product(list(range(H)), list(range(W))):

    if A[h][w] == '#':

        nexts.append((h, w))



delta = [[0, 1], [0, -1], [1, 0], [-1, 0]]

ans = 0

while nexts:

    nn = []

    for dh, dw in delta:

        for h, w in nexts:

            if ok(h + dh, w + dw):

                A[h + dh][w + dw] = '#'

                nn.append((h + dh, w + dw))

    if not nn:

        break

    ans += 1

    nexts = nn

print(ans)

import bisect

import heapq

import itertools

import math

import os

import re

import string

import sys

from collections import Counter, deque, defaultdict

from copy import deepcopy

from decimal import Decimal

from fractions import gcd

from functools import lru_cache, reduce

from operator import itemgetter



import numpy as np

from scipy.ndimage import distance_transform_cdt



if os.getenv("LOCAL"):

    sys.stdin = open("_in.txt", "r")



sys.setrecursionlimit(2147483647)

INF = float("inf")

IINF = 10 ** 18

MOD = 10 ** 9 + 7



H, W = list(map(int, sys.stdin.readline().split()))

A = np.array([list(sys.stdin.readline().rstrip()) for _ in range(H)]) == '.'

ret = distance_transform_cdt(A, metric='taxicab')

print((ret.max()))

import os
import itertools
import sys

if os.getenv("LOCAL"):
    sys.stdin = open("_in.txt", "r")
sys.setrecursionlimit(2147483647)
INF = float("inf")
IINF = 10**18
MOD = 10**9 + 7
H, W = list(map(int, sys.stdin.readline().split()))
A = [list(sys.stdin.readline().rstrip()) for _ in range(H)]


def ok(h, w):
    return 0 <= h < H and 0 <= w < W and A[h][w] == "."


nexts = []
for h, w in itertools.product(list(range(H)), list(range(W))):
    if A[h][w] == "#":
        nexts.append((h, w))
delta = [[0, 1], [0, -1], [1, 0], [-1, 0]]
ans = 0
while nexts:
    nn = []
    for dh, dw in delta:
        for h, w in nexts:
            if ok(h + dh, w + dw):
                A[h + dh][w + dw] = "#"
                nn.append((h + dh, w + dw))
    if not nn:
        break
    ans += 1
    nexts = nn
print(ans)

import bisect
import heapq
import itertools
import math
import os
import re
import string
import sys
from collections import Counter, deque, defaultdict
from copy import deepcopy
from decimal import Decimal
from fractions import gcd
from functools import lru_cache, reduce
from operator import itemgetter
import numpy as np
from scipy.ndimage import distance_transform_cdt

if os.getenv("LOCAL"):
    sys.stdin = open("_in.txt", "r")
sys.setrecursionlimit(2147483647)
INF = float("inf")
IINF = 10**18
MOD = 10**9 + 7
H, W = list(map(int, sys.stdin.readline().split()))
A = np.array([list(sys.stdin.readline().rstrip()) for _ in range(H)]) == "."
ret = distance_transform_cdt(A, metric="taxicab")
print((ret.max()))

+import bisect +import heapq +import itertools +import math -import itertools +import re +import string +from collections import Counter, deque, defaultdict +from copy import deepcopy +from decimal import Decimal +from fractions import gcd +from functools import lru_cache, reduce +from operator import itemgetter +import numpy as np +from scipy.ndimage import distance_transform_cdt -A = [list(sys.stdin.readline().rstrip()) for _ in range(H)] - - -def ok(h, w): -    return 0 <= h < H and 0 <= w < W and A[h][w] == "." - - -nexts = [] -for h, w in itertools.product(list(range(H)), list(range(W))): -    if A[h][w] == "#": -        nexts.append((h, w)) -delta = [[0, 1], [0, -1], [1, 0], [-1, 0]] -ans = 0 -while nexts: -    nn = [] -    for dh, dw in delta: -        for h, w in nexts: -            if ok(h + dh, w + dw): -                A[h + dh][w + dw] = "#" -                nn.append((h + dh, w + dw)) -    if not nn: -        break -    ans += 1 -    nexts = nn -print(ans) +A = np.array([list(sys.stdin.readline().rstrip()) for _ in range(H)]) == "." +ret = distance_transform_cdt(A, metric="taxicab") +print((ret.max()))