### 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 = []
    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:
        flg = 0
        pre_dic = set()
        for now_data in now_list:
            i, j = now_data
            data[i][j] = '#'

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

            if kari_i1 >= 0:
                if data[kari_i1][j] == '.' and [kari_i1, j] not in next_list:
                    next_list.append([kari_i1, j])
                    flg = 1
            if kari_i2 <= high - 1:
                if data[kari_i2][j] == '.' and [kari_i2, j] not in next_list:
                    next_list.append([kari_i2, j])
                    flg = 1
            if kari_j1 >= 0:
                if data[i][kari_j1] == '.' and [i, kari_j1] not in next_list:
                    next_list.append([i, kari_j1])
                    flg = 1
            if kari_j2 <= width - 1:
                if data[i][kari_j2] == '.' and [i, kari_j2] not in next_list:
                    next_list.append([i, kari_j2])
                    flg = 1

        now_list = next_list.copy()
        next_list = []

        # print('uuuu')
        # print(i, j)
        # print(now_list)


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

        # check_count = count
        # count = str(int(count) + 1)

        # print('------')
        # for i in range(high):
        #     print(''.join(data[i]))
    #
    # print('------')
    # for i in range(high):
    #     print(''.join(data[i]))

    # print(check_count)

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