### BUGGY CODE ###

# AtCoder Grand Contest 033
# https://atcoder.jp/contests/agc033
import sys
import datetime
today = datetime.datetime.today

s2nn = lambda s: [int(c) for c in s.split(' ')]
ss2nn = lambda ss: [int(s) for s in list(ss)]
ss2nnn = lambda ss: [s2nn(s) for s in list(ss)]
i2s = lambda: sys.stdin.readline().rstrip()
i2n = lambda: int(i2s())
i2nn = lambda: s2nn(i2s())
ii2ss = lambda n: [sys.stdin.readline().rstrip() for _ in range(n)]
ii2nn = lambda n: ss2nn(ii2ss(n))
ii2nnn = lambda n: ss2nnn(ii2ss(n))

def main_ok():
    H, W = i2nn()
    HW = H * W
    A = ii2ss(H)
    A = [[0 if s == '#' else HW for s in line] for line in A]
    for i in range(H):
        for j in range(1, W):
            if A[i][j-1]+1 < A[i][j]:
                A[i][j] = A[i][j-1]+1
        for j in range(W-2, -1, -1):
            if A[i][j+1]+1 < A[i][j]:
                A[i][j] = A[i][j+1]+1
    for j in range(W):
        for i in range(1, H):
            if A[i-1][j]+1 < A[i][j]:
                A[i][j] = A[i-1][j]+1
        for i in range(H-2, -1, -1):
            if A[i+1][j]+1 < A[i][j]:
                A[i][j] = A[i+1][j]+1
    ans = 0
    for i in range(H):
        for j in range(W):
            if A[i][j] > ans:
                ans = A[i][j]
    print(ans)

def tk(i, j):
    return i * 10000 + j
def dk(key):
    i = int(key / 10000)
    j = key % 10000
    return i, j

def main():
    H, W = i2nn()
    A = ii2ss(H)
    st0 = set()
    st1 = set()
    for j in range(-1, W+1):
        st0.add(tk(-1, j))
        st0.add(tk(H, j))
    for i in range(H):
        st0.add(tk(i, -1))
        st0.add(tk(i, W))
        for j in range(W):
            if A[i][j] == '#':
                st0.add(tk(i, j))
                st1.add(tk(i, j))
    rec = 0
    while len(st1) > 0:
        st2 = set()
        for key in st1:
            i, j = dk(key)
            k2 = tk(i-1, j)
            if k2 not in st0:
                st0.add(k2)
                st2.add(k2)
            k2 = tk(i+1, j)
            if k2 not in st0:
                st0.add(k2)
                st2.add(k2)
            k2 = tk(i, j-1)
            if k2 not in st0:
                st0.add(k2)
                st2.add(k2)
            k2 = tk(i, j+1)
            if k2 not in st0:
                st0.add(k2)
                st2.add(k2)
        rec += 1
        st1 = st2
    print(rec - 1)

main()


### FIXED CODE ###

# AtCoder Grand Contest 033
# https://atcoder.jp/contests/agc033
import sys

s2nn = lambda s: [int(c) for c in s.split(' ')]
ss2nn = lambda ss: [int(s) for s in list(ss)]
ss2nnn = lambda ss: [s2nn(s) for s in list(ss)]
i2s = lambda: sys.stdin.readline().rstrip()
i2n = lambda: int(i2s())
i2nn = lambda: s2nn(i2s())
ii2ss = lambda n: [sys.stdin.readline() for _ in range(n)]
ii2nn = lambda n: ss2nn(ii2ss(n))
ii2nnn = lambda n: ss2nnn(ii2ss(n))

import datetime

def main():
    H, W = i2nn()
    HW = H * W
    A = ii2ss(H)
    A = [[0 if s == '#' else HW for s in line] for line in A]
    for i in range(H):
        for j in range(1, W):
            if A[i][j-1]+1 < A[i][j]:
                A[i][j] = A[i][j-1]+1
        for j in range(W-2, -1, -1):
            if A[i][j+1]+1 < A[i][j]:
                A[i][j] = A[i][j+1]+1
    for j in range(W):
        for i in range(1, H):
            if A[i-1][j]+1 < A[i][j]:
                A[i][j] = A[i-1][j]+1
        for i in range(H-2, -1, -1):
            if A[i+1][j]+1 < A[i][j]:
                A[i][j] = A[i+1][j]+1
    ans = 0
    for i in range(H):
        for j in range(W):
            if A[i][j] > ans:
                ans = A[i][j]
    print(ans)

main()