import sys

import collections





def solve():

    readline = sys.stdin.buffer.readline

    mod = 10 ** 9 + 7

    h, w = list(map(int, readline().split()))

    a = [list(str(readline().rstrip().decode('utf-8'))) for _ in range(h)]

    fq = [[True] * w for _ in range(h)]

    ql = collections.deque()

    for i in range(h):

        for j in range(w):

            if a[i][j] == "#":

                fq[i][j] = False

                ql.append([0, i, j])

    mt = 0

    while True:

        if len(ql) != 0:

            cost, x, y = ql.popleft()

            mt = max(mt, cost)

            for xv, yv in [[x + 1, y], [x - 1, y], [x, y + 1], [x, y - 1]]:

                if 0 <= xv < h and 0 <= yv < w:

                    if fq[xv][yv]:

                        ql.append([cost + 1, xv, yv])

                        fq[xv][yv] = False

        else:

            break

    print(mt)





if __name__ == '__main__':

    solve()

import sys

import collections





def solve():

    readline = sys.stdin.buffer.readline

    mod = 10 ** 9 + 7

    h, w = list(map(int, readline().split()))

    a = []

    ql = collections.deque()

    for i in range(h):

        al = list(str(readline().rstrip().decode('utf-8')))

        ta = []

        for j in range(w):

            if al[j] == ".":

                ta.append(True)

            else:

                ta.append(False)

                ql.append([0, i, j])

        a.append(ta)



    mc = 0

    while True:

        if len(ql) != 0:

            cost, xv, yv = ql.popleft()

            mc = max(mc, cost)

            for xv, yv in [[xv + 1, yv], [xv - 1, yv], [xv, yv + 1], [xv, yv - 1]]:

                if 0 <= xv < h and 0 <= yv < w:

                    if a[xv][yv]:

                        ql.append([cost + 1, xv, yv])

                        a[xv][yv] = False

        else:

            break

    print(mc)





if __name__ == '__main__':

    solve()

import sys
import collections


def solve():
    readline = sys.stdin.buffer.readline
    mod = 10**9 + 7
    h, w = list(map(int, readline().split()))
    a = [list(str(readline().rstrip().decode("utf-8"))) for _ in range(h)]
    fq = [[True] * w for _ in range(h)]
    ql = collections.deque()
    for i in range(h):
        for j in range(w):
            if a[i][j] == "#":
                fq[i][j] = False
                ql.append([0, i, j])
    mt = 0
    while True:
        if len(ql) != 0:
            cost, x, y = ql.popleft()
            mt = max(mt, cost)
            for xv, yv in [[x + 1, y], [x - 1, y], [x, y + 1], [x, y - 1]]:
                if 0 <= xv < h and 0 <= yv < w:
                    if fq[xv][yv]:
                        ql.append([cost + 1, xv, yv])
                        fq[xv][yv] = False
        else:
            break
    print(mt)


if __name__ == "__main__":
    solve()

import sys
import collections


def solve():
    readline = sys.stdin.buffer.readline
    mod = 10**9 + 7
    h, w = list(map(int, readline().split()))
    a = []
    ql = collections.deque()
    for i in range(h):
        al = list(str(readline().rstrip().decode("utf-8")))
        ta = []
        for j in range(w):
            if al[j] == ".":
                ta.append(True)
            else:
                ta.append(False)
                ql.append([0, i, j])
        a.append(ta)
    mc = 0
    while True:
        if len(ql) != 0:
            cost, xv, yv = ql.popleft()
            mc = max(mc, cost)
            for xv, yv in [[xv + 1, yv], [xv - 1, yv], [xv, yv + 1], [xv, yv - 1]]:
                if 0 <= xv < h and 0 <= yv < w:
                    if a[xv][yv]:
                        ql.append([cost + 1, xv, yv])
                        a[xv][yv] = False
        else:
            break
    print(mc)


if __name__ == "__main__":
    solve()

-    a = [list(str(readline().rstrip().decode("utf-8"))) for _ in range(h)] -    fq = [[True] * w for _ in range(h)] +    a = [] +        al = list(str(readline().rstrip().decode("utf-8"))) +        ta = [] -            if a[i][j] == "#": -                fq[i][j] = False +            if al[j] == ".": +                ta.append(True) +            else: +                ta.append(False) -    mt = 0 +        a.append(ta) +    mc = 0 -            cost, x, y = ql.popleft() -            mt = max(mt, cost) -            for xv, yv in [[x + 1, y], [x - 1, y], [x, y + 1], [x, y - 1]]: +            cost, xv, yv = ql.popleft() +            mc = max(mc, cost) +            for xv, yv in [[xv + 1, yv], [xv - 1, yv], [xv, yv + 1], [xv, yv - 1]]: -                    if fq[xv][yv]: +                    if a[xv][yv]: -                        fq[xv][yv] = False +                        a[xv][yv] = False -    print(mt) +    print(mc)