### BUGGY CODE ###


from collections import defaultdict
import math

def kari():
    map(int, input().split())
    list(map(int, input().split()))


def main():
    high, width = map(int, input().split())
    data = [list(input()) for i in range(high)]

    now_list = set()
    next_list = set()
    for i in range(high):
        for j in range(width):
            if data[i][j] == '#':
                now_list.add('{}_{}'.format(i, j))


    count = 0

    while 1:
        flg = 0
        for now_data in now_list:
            i, j = map(int, now_data.split('_'))
            data[i][j] = '#'

            kari_i1, kari_i2 = i - 1, i + 1
            kari_j1, kari_j2 = j - 1, j + 1

            if kari_i1 >= 0:
                a, b = kari_i1, j
                c = '{}_{}'.format(a, b)
                if data[a][b] == '.':
                    if c not in next_list:
                        next_list.add(c)
                        flg = 1

            if kari_i2 <= high - 1:
                a, b = kari_i2, j
                c = '{}_{}'.format(a, b)
                if data[a][b] == '.':
                    if c not in next_list:
                        next_list.add(c)
                        flg = 1

            if kari_j1 >= 0:
                a, b = i, kari_j1
                c = '{}_{}'.format(a, b)
                if data[a][b] == '.':
                    if c not in next_list:
                        next_list.add(c)
                        flg = 1

            if kari_j2 <= width - 1:
                a, b = i, kari_j2
                c = '{}_{}'.format(a, b)
                if data[a][b] == '.':
                    if c not in next_list:
                        next_list.add(c)
                        flg = 1

        now_list = next_list
        next_list = set()


        if flg == 0:
            break
        else:
            count += 1


    print(count)




if __name__ == '__main__':
    main()

### FIXED CODE ###

def main():
    high, width = map(int, input().split())
    data = [list(input()) for i in range(high)]

    now_list = []
    next_list = []

    for i in range(high):
        for j in range(width):
            if data[i][j] == '#':
                now_list.append([i, j])

    count = 0

    while 1:
        for now_data in now_list:
            i, j = now_data

            kari_i1, kari_i2 = i - 1, i + 1
            kari_j1, kari_j2 = j - 1, j + 1

            if kari_i1 >= 0:
                a, b = kari_i1, j
                if data[a][b] == '.':
                    next_list.append([a, b])
                    data[a][b] = '#'

            if kari_i2 <= high - 1:
                a, b = kari_i2, j
                if data[a][b] == '.':
                    next_list.append([a, b])
                    data[a][b] = '#'

            if kari_j1 >= 0:
                a, b = i, kari_j1
                if data[a][b] == '.':
                    next_list.append([a, b])
                    data[a][b] = '#'

            if kari_j2 <= width - 1:
                a, b = i, kari_j2
                if data[a][b] == '.':
                    next_list.append([a, b])
                    data[a][b] = '#'

        now_list = next_list
        next_list = []


        if len(now_list) == 0:
            break
        else:
            count += 1


    print(count)



if __name__ == '__main__':
    main()