h,w = map(int, input().split())
d = []
for i in range(h):
    d.append(list(input()))

c = 0
while True:
    fin = False
    for i in range(len(d)):
        for j in range(len(d[i])):
            if d[i][j] == ".":
                fin = True
    if fin is False:
        break
    hw_list = []
    dark = []
    for i in range(h):
        for j in range(w):
            if d[i][j] == "#":
                dark.append((i,j))
                hw_list.extend([(i,j+1),(i,j-1),(i+1,j),(i-1,j)])
    hw_list = list(set(hw_list)-set(dark))
    hw = [j for j in hw_list if min(j) >= 0 and j[0] < h and j[1] < w]
    for i in range(len(hw)):
        d[hw[i][0]][hw[i][1]] = "#"
    c += 1

print(c)
    