### BUGGY CODE ###

import sys
sys.setrecursionlimit(10**7)
from collections import deque
def solve():
    H,W = map(int, input().split())
    A = [ input() for _ in range(H)]
    HMANY = [ [10**9] * W for _ in range(H)]

    
    # def dfs(h,w,num,H,W,A,HMANY):
    #     if HMANY[h][w] > num:
    #         HMANY[h][w] = num
    #         if h+1 <H:
    #             dfs(h+1,w,num+1,H,W,A,HMANY)
    #         if w+1 <W:
    #             dfs(h,w+1,num+1,H,W,A,HMANY)
    #         if 0<=h-1:
    #             dfs(h-1,w,num+1, H,W,A,HMANY)
    #         if 0<=w-1:
    #             dfs(h,w-1,num+1, H,W,A,HMANY)
    
    q = deque()
    p = deque()
    for h in range(H):
        for w in range(W):
            if A[h][w] == "#" :
                q.append((h,w,0))
                p.append((h,w))
                # dfs(h,w,0,H,W,A,HMANY)
    while q:
        h,w,num = q.popleft()
        h,w     = p.popleft()
        if HMANY[h][w] > num:
            HMANY[h][w] = num
            if h+1 <H and not (h+1,w) in p:
                q.append((h+1,w,num+1))
                p.append((h+1,w))
            if w+1 <W and not (h,w+1) in p:
                q.append((h,w+1,num+1))
                p.append((h,w+1))
            if 0<=h-1 and not (h-1,w) in p:
                q.append((h-1,w,num+1))
                p.append((h-1,w)                )
            if 0<=w-1 and not (h,w-1) in p:
                q.append((h,w-1,num+1))
                p.append((h,w-1)        )

    ans = 0
    for h in range(H):
        ans = max(ans, max(HMANY[h]))
    print(ans)

if __name__ == "__main__":
    solve()

### FIXED CODE ###

import sys
sys.setrecursionlimit(10**7)
from collections import deque
from heapq import heappush, heappop
def solve():
    H,W = map(int, input().split())
    A = [ list(input()) for _ in range(H)]
    HMANY = [ [10**9] * W for _ in range(H)]

    
    
    # q = deque()
    for h in range(H):
        for w in range(W):
            if A[h][w] == "#" :
                HMANY[h][w] = 0
    for w in range(W):
        for h in range(H-1):
            if HMANY[h][w]+1 < HMANY[h+1][w]:
                HMANY[h+1][w] = HMANY[h][w] + 1
        for h in range(H-1, 0, -1):
            if HMANY[h][w]+1 < HMANY[h-1][w]:
                HMANY[h-1][w] = HMANY[h][w] + 1
    
    for h in range(H):
        for w in range(W-1):
            if HMANY[h][w]+1 < HMANY[h][w+1]:
                HMANY[h][w+1] = HMANY[h][w] + 1
        for w in range(W-1, 0, -1):
            if HMANY[h][w]+1 < HMANY[h][w-1]:
                HMANY[h][w-1] = HMANY[h][w] + 1        
    #             q.append((h,w))
    #             A[h][w] = "."
    # ans = 0
    # while q:
    #     nextQ = deque()
    #     for h,w in q:
    #         A[h][w] = "#"
    #         if h+1 <H and A[h+1][w] == ".":
    #             nextQ.append( (h+1,w))
    #         if w+1 <W and A[h][w+1] == ".":
    #             nextQ.append((h,w+1))
    #         if 0<=h-1 and A[h-1][w] == ".":
    #             nextQ.append((h-1,w))
    #         if 0<=w-1 and A[h][w-1] == ".":
    #             nextQ.append((h,w-1))        
    #     ans += 1
    #     q = nextQ
        # num,h,w = q.popleft()        
        # if HMANY[h][w] > num and A[h][w] == ".":
        #     HMANY[h][w] = num
        #     A[h][w] = "#"
        #     if h+1 <H and A[h+1][w] == ".":
        #         q.append( (num+1,h+1,w))
        #     if w+1 <W and A[h][w+1] == ".":
        #         q.append((num+1,h,w+1))
        #     if 0<=h-1 and A[h-1][w] == ".":
        #         q.append((num+1,h-1,w))
        #     if 0<=w-1 and A[h][w-1] == ".":
        #         q.append((num+1,h,w-1))

    ans = 0
    for h in range(H):
        ans = max(ans, max(HMANY[h]))
    # print(ans-1)
    print(ans)

if __name__ == "__main__":
    solve()