### BUGGY CODE ###

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] == '#':
                c = '{}_{}'.format(i, j)
                now_list.add(c)

    count = 0

    while 1:
        for now_data in now_list:
            i, j = map(int, now_data.split('_'))

            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] == '.':
                    c = '{}_{}'.format(a, b)
                    next_list.add(c)
                    data[a][b] = '#'

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

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

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

        now_list = next_list
        next_list = set()


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


    print(count)

def kari():
    high, width = 1000, 1000
    a = set()
    for i in range(high):
        for j in range(width):
            a.add(j)
        a = set()

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()