import numpy as np



H,W = list(map(int,input().split()))

use = np.zeros((H,W),dtype=int)

for i in range(H):

    s = eval(input())

    for j,st in enumerate(s):

        if st == ".":

            use[i][j] = 10**9



for i in range(1,H):

    use[i,:] = np.minimum(use[i,:],use[i-1,:]+1)

for i in reversed(list(range(H-1))):

    use[i,:] = np.minimum(use[i,:],use[i+1,:]+1)

for j in range(1,W):

    use[:,j] = np.minimum(use[:,j],use[:,j-1]+1)

for j in reversed(list(range(W-1))):

    use[:,j] = np.minimum(use[:,j],use[:,j+1]+1)



print((np.max(use)))
import numpy as np



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

visited = np.zeros((h,w),dtype=int)



for y in range(h):

    _in = eval(input())

    for x, value in enumerate(_in):

        if value == '.':

            visited[y][x] = 10**9

            

for i in range(1,h):

    visited[i,:] = np.minimum(visited[i,:],visited[i-1,:]+1)

for i in reversed(list(range(h-1))):

    visited[i,:] = np.minimum(visited[i,:],visited[i+1,:]+1)

for j in range(1,w):

    visited[:,j] = np.minimum(visited[:,j],visited[:,j-1]+1)

for j in reversed(list(range(w-1))):

    visited[:,j] = np.minimum(visited[:,j],visited[:,j+1]+1)

print((np.max(visited)))
import numpy as np

H, W = list(map(int, input().split()))
use = np.zeros((H, W), dtype=int)
for i in range(H):
    s = eval(input())
    for j, st in enumerate(s):
        if st == ".":
            use[i][j] = 10**9
for i in range(1, H):
    use[i, :] = np.minimum(use[i, :], use[i - 1, :] + 1)
for i in reversed(list(range(H - 1))):
    use[i, :] = np.minimum(use[i, :], use[i + 1, :] + 1)
for j in range(1, W):
    use[:, j] = np.minimum(use[:, j], use[:, j - 1] + 1)
for j in reversed(list(range(W - 1))):
    use[:, j] = np.minimum(use[:, j], use[:, j + 1] + 1)
print((np.max(use)))

import numpy as np

h, w = list(map(int, input().split()))
visited = np.zeros((h, w), dtype=int)
for y in range(h):
    _in = eval(input())
    for x, value in enumerate(_in):
        if value == ".":
            visited[y][x] = 10**9
for i in range(1, h):
    visited[i, :] = np.minimum(visited[i, :], visited[i - 1, :] + 1)
for i in reversed(list(range(h - 1))):
    visited[i, :] = np.minimum(visited[i, :], visited[i + 1, :] + 1)
for j in range(1, w):
    visited[:, j] = np.minimum(visited[:, j], visited[:, j - 1] + 1)
for j in reversed(list(range(w - 1))):
    visited[:, j] = np.minimum(visited[:, j], visited[:, j + 1] + 1)
print((np.max(visited)))

-H, W = list(map(int, input().split())) -use = np.zeros((H, W), dtype=int) -for i in range(H): -    s = eval(input()) -    for j, st in enumerate(s): -        if st == ".": -            use[i][j] = 10**9 -for i in range(1, H): -    use[i, :] = np.minimum(use[i, :], use[i - 1, :] + 1) -for i in reversed(list(range(H - 1))): -    use[i, :] = np.minimum(use[i, :], use[i + 1, :] + 1) -for j in range(1, W): -    use[:, j] = np.minimum(use[:, j], use[:, j - 1] + 1) -for j in reversed(list(range(W - 1))): -    use[:, j] = np.minimum(use[:, j], use[:, j + 1] + 1) -print((np.max(use))) +h, w = list(map(int, input().split())) +visited = np.zeros((h, w), dtype=int) +for y in range(h): +    _in = eval(input()) +    for x, value in enumerate(_in): +        if value == ".": +            visited[y][x] = 10**9 +for i in range(1, h): +    visited[i, :] = np.minimum(visited[i, :], visited[i - 1, :] + 1) +for i in reversed(list(range(h - 1))): +    visited[i, :] = np.minimum(visited[i, :], visited[i + 1, :] + 1) +for j in range(1, w): +    visited[:, j] = np.minimum(visited[:, j], visited[:, j - 1] + 1) +for j in reversed(list(range(w - 1))): +    visited[:, j] = np.minimum(visited[:, j], visited[:, j + 1] + 1) +print((np.max(visited)))