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

a = [list(eval(input())) for _ in range(h)]

d = (-1, 0), (1, 0), (0, -1), (0, 1)

p = [(i, j) for i in range(h) for j in range(w) if a[i][j] == '#']

n = h * w - len(p)

r = 0

while n:

    r += 1

    s = []

    for i, j in p:

        for di, dj in d:

            di += i

            dj += j

            if 0 <= di < h and 0 <= dj < w and a[di][dj] == '.':

                a[di][dj] = '#'

                s.append((di, dj))

    p = s

    n -= len(p)

print(r)

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

a = [list(eval(input())) for _ in range(h)]

d = (-1, 0), (1, 0), (0, -1), (0, 1)

p = [(i, j) for i in range(h) for j in range(w) if a[i][j] == '#']



def f():

    s = []

    for i, j in p:

        for di, dj in d:

            di += i

            dj += j

            if 0 <= di < h and 0 <= dj < w and a[di][dj] == '.':

                a[di][dj] = '#'

                s.append((di, dj))

    return s



n = h * w - len(p)

r = 0

while n:

    r += 1

    p = f()

    n -= len(p)

print(r)

h, w = list(map(int, input().split()))
a = [list(eval(input())) for _ in range(h)]
d = (-1, 0), (1, 0), (0, -1), (0, 1)
p = [(i, j) for i in range(h) for j in range(w) if a[i][j] == "#"]
n = h * w - len(p)
r = 0
while n:
    r += 1
    s = []
    for i, j in p:
        for di, dj in d:
            di += i
            dj += j
            if 0 <= di < h and 0 <= dj < w and a[di][dj] == ".":
                a[di][dj] = "#"
                s.append((di, dj))
    p = s
    n -= len(p)
print(r)

h, w = list(map(int, input().split()))
a = [list(eval(input())) for _ in range(h)]
d = (-1, 0), (1, 0), (0, -1), (0, 1)
p = [(i, j) for i in range(h) for j in range(w) if a[i][j] == "#"]


def f():
    s = []
    for i, j in p:
        for di, dj in d:
            di += i
            dj += j
            if 0 <= di < h and 0 <= dj < w and a[di][dj] == ".":
                a[di][dj] = "#"
                s.append((di, dj))
    return s


n = h * w - len(p)
r = 0
while n:
    r += 1
    p = f()
    n -= len(p)
print(r)

-n = h * w - len(p) -r = 0 -while n: -    r += 1 + + +def f(): -    p = s +    return s + + +n = h * w - len(p) +r = 0 +while n: +    r += 1 +    p = f()