### BUGGY CODE ###

# coding: utf-8
# Your code here!

from collections import deque
import numpy as np


H, W = map(int, input().rstrip().split(' '))

field = []
for _ in range(H):
    temp_field = []
    for s in input():
        if s == '.':
            temp_field.append(0)
        else:
            temp_field.append(1)
    field.append(temp_field)

dp = [[H + W] * W for _ in range(H)]
dp2 = [[False] * W for _ in range(H)]
lists = np.zeros((H*W, 2), dtype=int)


count2 = 0
for i in range(H):
    for j in range(W):
        if field[i][j] == 1:
            dp[i][j] = 0
            dp2[i][j] = True
            if i > 0:
                #lists.append([i-1, j])
                dp2[i-1][j] = True
                lists[count2][0] = i - 1
                lists[count2][1] = j
                count2 += 1
            if i < H - 1:
                #lists.append([i+1, j])
                dp2[i+1][j] = True
                lists[count2][0] = i + 1
                lists[count2][1] = j
                count2 += 1
            if j > 0:
                #lists.append([i, j-1])
                dp2[i][j-1] = True
                lists[count2][0] = i
                lists[count2][1] = j - 1
                count2 += 1
            if j < W - 1:
                #lists.append([i, j+1])
                dp2[i][j+1] = True
                lists[count2][0] = i
                lists[count2][1] = j + 1
                count2 += 1
      

count = 0
while True:
    if count2 <= count:
        break
    
    if count > 1000 * 1000:
        break
    
    #i, j = lists.popleft()
    #i, j = lists[count]
    i = lists[count][0]
    j = lists[count][1]
    #print(i, j, dp2, lists)
    #if dp2[i][j] == True:
     #   continue
    #else:
    #    dp2[i][j] = True
        
    min_dist = H + W
    if i > 0:
        min_dist = min(min_dist, dp[i-1][j] + 1)
        if dp2[i-1][j] == False:
            #lists.append([i-1, j])
            dp2[i-1][j] = True
            lists[count2][0] = i - 1
            lists[count2][1] = j
            count2 += 1
    if i < H - 1:
        min_dist = min(min_dist, dp[i+1][j] + 1)
        if dp2[i+1][j] == False:
            #lists.append([i+1, j])
            dp2[i+1][j] = True
            lists[count2][0] = i + 1
            lists[count2][1] = j
            count2 += 1
    if j > 0:
        min_dist = min(min_dist, dp[i][j-1] + 1)
        if dp2[i][j-1] == False:
            #lists.append([i, j-1])
            dp2[i][j-1] = True
            lists[count2][0] = i
            lists[count2][1] = j - 1
            count2 += 1
    if j < W - 1:
        min_dist = min(min_dist, dp[i][j+1] + 1)
        if dp2[i][j+1] == False:
            #lists.append([i, j+1])
            dp2[i][j+1] = True
            lists[count2][0] = i
            lists[count2][1] = j + 1
            count2 += 1
        
    dp[i][j] = min_dist
    count += 1


        
print(max([max(temp_dp) for temp_dp in dp]))

### FIXED CODE ###

# coding: utf-8
# Your code here!

from collections import deque

H, W = map(int, input().rstrip().split(' '))

field = [[0] * W for _ in range(H)]
d = deque()
for i in range(H):
    s = input()
    for j in range(W):
        if s[j] == '#':
            field[i][j] = 1
            d.append([i, j, 0])

max_dist = 0
while len(d) > 0:
    cur_h, cur_w, dist = d.popleft()
    for i, (dh, dw) in enumerate([[0, 1], [0, -1], [1, 0], [-1, 0]]):
        if (cur_h + dh) >= 0 and (cur_h + dh) < H and (cur_w + dw) >= 0 and (cur_w + dw) < W:
            if field[cur_h+dh][cur_w+dw] == 0:
                field[cur_h+dh][cur_w+dw] = 1
                d.append([cur_h+dh, cur_w+dw, dist+1])
                max_dist = max(max_dist, dist+1)

print(max_dist)