import sys



readline = sys.stdin.readline

MOD = 10 ** 9 + 7

INF = float('INF')

sys.setrecursionlimit(10 ** 5)





def main():

    from collections import deque, defaultdict



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

    que = deque()

    grid = [["#"] * (w + 2)]



    for row in range(1, h + 1):

        s = eval(input())

        for col, c in enumerate(s, 1):

            if c == "#":

                que.append((row, col, 0))

        grid.append(["#"] + list(s) + ["#"])



    grid.append(["#"] * (w + 2))

    direction = [(0, 1), (1, 0), (-1, 0), (0, -1)]

    cnt = 0



    while que:

        cr, cc, cnt = que.popleft()

        for mr, mc in direction:

            nr, nc = cr + mr, cc + mc

            if grid[nr][nc] == ".":

                que.append((nr, nc, cnt + 1))

                grid[nr][nc] = "#"



    print(cnt)





if __name__ == '__main__':

    main()

import sys



readline = sys.stdin.readline

MOD = 10 ** 9 + 7

INF = float('INF')

sys.setrecursionlimit(10 ** 5)





def main():

    from collections import deque



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

    que = deque()

    grid = [[] for _ in range(h + 2)]

    grid[0] = ["#"] * (w + 2)

    grid[-1] = ["#"] * (w + 2)



    for row in range(1, h + 1):

        s = eval(input())

        for col, c in enumerate(s, 1):

            if c == "#":

                que.append((row, col, 0))

        grid[row] = ["#"] + list(s) + ["#"]



    cnt = 0



    while que:

        cr, cc, cnt = que.popleft()

        if grid[cr + 1][cc] == ".":

            que.append((cr + 1, cc, cnt + 1))

            grid[cr + 1][cc] = "#"

        if grid[cr - 1][cc] == ".":

            que.append((cr - 1, cc, cnt + 1))

            grid[cr - 1][cc] = "#"

        if grid[cr][cc + 1] == ".":

            que.append((cr, cc + 1, cnt + 1))

            grid[cr][cc + 1] = "#"

        if grid[cr][cc - 1] == ".":

            que.append((cr, cc - 1, cnt + 1))

            grid[cr][cc - 1] = "#"

    print(cnt)





if __name__ == '__main__':

    main()

import sys

readline = sys.stdin.readline
MOD = 10**9 + 7
INF = float("INF")
sys.setrecursionlimit(10**5)


def main():
    from collections import deque, defaultdict

    h, w = list(map(int, readline().split()))
    que = deque()
    grid = [["#"] * (w + 2)]
    for row in range(1, h + 1):
        s = eval(input())
        for col, c in enumerate(s, 1):
            if c == "#":
                que.append((row, col, 0))
        grid.append(["#"] + list(s) + ["#"])
    grid.append(["#"] * (w + 2))
    direction = [(0, 1), (1, 0), (-1, 0), (0, -1)]
    cnt = 0
    while que:
        cr, cc, cnt = que.popleft()
        for mr, mc in direction:
            nr, nc = cr + mr, cc + mc
            if grid[nr][nc] == ".":
                que.append((nr, nc, cnt + 1))
                grid[nr][nc] = "#"
    print(cnt)


if __name__ == "__main__":
    main()

import sys

readline = sys.stdin.readline
MOD = 10**9 + 7
INF = float("INF")
sys.setrecursionlimit(10**5)


def main():
    from collections import deque

    h, w = list(map(int, readline().split()))
    que = deque()
    grid = [[] for _ in range(h + 2)]
    grid[0] = ["#"] * (w + 2)
    grid[-1] = ["#"] * (w + 2)
    for row in range(1, h + 1):
        s = eval(input())
        for col, c in enumerate(s, 1):
            if c == "#":
                que.append((row, col, 0))
        grid[row] = ["#"] + list(s) + ["#"]
    cnt = 0
    while que:
        cr, cc, cnt = que.popleft()
        if grid[cr + 1][cc] == ".":
            que.append((cr + 1, cc, cnt + 1))
            grid[cr + 1][cc] = "#"
        if grid[cr - 1][cc] == ".":
            que.append((cr - 1, cc, cnt + 1))
            grid[cr - 1][cc] = "#"
        if grid[cr][cc + 1] == ".":
            que.append((cr, cc + 1, cnt + 1))
            grid[cr][cc + 1] = "#"
        if grid[cr][cc - 1] == ".":
            que.append((cr, cc - 1, cnt + 1))
            grid[cr][cc - 1] = "#"
    print(cnt)


if __name__ == "__main__":
    main()

-    from collections import deque, defaultdict +    from collections import deque -    grid = [["#"] * (w + 2)] +    grid = [[] for _ in range(h + 2)] +    grid[0] = ["#"] * (w + 2) +    grid[-1] = ["#"] * (w + 2) -        grid.append(["#"] + list(s) + ["#"]) -    grid.append(["#"] * (w + 2)) -    direction = [(0, 1), (1, 0), (-1, 0), (0, -1)] +        grid[row] = ["#"] + list(s) + ["#"] -        for mr, mc in direction: -            nr, nc = cr + mr, cc + mc -            if grid[nr][nc] == ".": -                que.append((nr, nc, cnt + 1)) -                grid[nr][nc] = "#" +        if grid[cr + 1][cc] == ".": +            que.append((cr + 1, cc, cnt + 1)) +            grid[cr + 1][cc] = "#" +        if grid[cr - 1][cc] == ".": +            que.append((cr - 1, cc, cnt + 1)) +            grid[cr - 1][cc] = "#" +        if grid[cr][cc + 1] == ".": +            que.append((cr, cc + 1, cnt + 1)) +            grid[cr][cc + 1] = "#" +        if grid[cr][cc - 1] == ".": +            que.append((cr, cc - 1, cnt + 1)) +            grid[cr][cc - 1] = "#"