import sys

sys.setrecursionlimit(10**6)

input = sys.stdin.readline



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

INF = 10**18

q = []



visited = [[True]*(W+2)]

visited += [[True] + [x == '#' for x in input().rstrip()] + [True] for _ in range(H)]

visited.append([True]*(W+2))

  

for i in range(1,H+1):

  for j in range(1,W+1):

    if visited[i][j]:

      q.append((i,j))



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



ans = -1

while q:

  qq = []

  ans += 1

  for x,y in q:

    if not visited[x-1][y]:

      visited[x-1][y] = True

      qq.append((x-1,y))

    if not visited[x+1][y]:

      visited[x+1][y] = True

      qq.append((x+1,y))

    if not visited[x][y-1]:

      visited[x][y-1] = True

      qq.append((x,y-1))

    if not visited[x][y+1]:

      visited[x][y+1] = True

      qq.append((x,y+1))

  q = qq

  

print(ans)
import sys

sys.setrecursionlimit(10**6)

input = sys.stdin.readline



def main():

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



    # 番兵法 (#を外周に設置する)

    visited = [[True]*(W+2)]

    visited += [[True] + [x == '#' for x in input().rstrip()] + [True] for _ in range(H)]

    visited.append([True]*(W+2))



    # #の位置をqに格納

    q = []

    for i in range(1,H+1):

        for j in range(1,W+1):

            if visited[i][j]:

                q.append((i,j))



    # dx,dyを使用せずにBFS 

    # 定数倍改善

    ans = -1

    while q:

        qq = []

        # 新たに#となった地点をqqに格納

        for x,y in q:

            if not visited[x-1][y]:

                visited[x-1][y] = True

                qq.append((x-1,y))

            if not visited[x+1][y]:

                visited[x+1][y] = True

                qq.append((x+1,y))

            if not visited[x][y-1]:

                visited[x][y-1] = True

                qq.append((x,y-1))

            if not visited[x][y+1]:

                visited[x][y+1] = True

                qq.append((x,y+1))

        q = qq

        ans += 1

    

    print(ans)



if __name__ == '__main__':

    main()
import sys

sys.setrecursionlimit(10**6)
input = sys.stdin.readline
H, W = list(map(int, input().split()))
INF = 10**18
q = []
visited = [[True] * (W + 2)]
visited += [[True] + [x == "#" for x in input().rstrip()] + [True] for _ in range(H)]
visited.append([True] * (W + 2))
for i in range(1, H + 1):
    for j in range(1, W + 1):
        if visited[i][j]:
            q.append((i, j))
moves = [(0, 1), (0, -1), (1, 0), (-1, 0)]
ans = -1
while q:
    qq = []
    ans += 1
    for x, y in q:
        if not visited[x - 1][y]:
            visited[x - 1][y] = True
            qq.append((x - 1, y))
        if not visited[x + 1][y]:
            visited[x + 1][y] = True
            qq.append((x + 1, y))
        if not visited[x][y - 1]:
            visited[x][y - 1] = True
            qq.append((x, y - 1))
        if not visited[x][y + 1]:
            visited[x][y + 1] = True
            qq.append((x, y + 1))
    q = qq
print(ans)

import sys

sys.setrecursionlimit(10**6)
input = sys.stdin.readline


def main():
    H, W = list(map(int, input().split()))
    # 番兵法 (#を外周に設置する)
    visited = [[True] * (W + 2)]
    visited += [
        [True] + [x == "#" for x in input().rstrip()] + [True] for _ in range(H)
    ]
    visited.append([True] * (W + 2))
    # #の位置をqに格納
    q = []
    for i in range(1, H + 1):
        for j in range(1, W + 1):
            if visited[i][j]:
                q.append((i, j))
    # dx,dyを使用せずにBFS
    # 定数倍改善
    ans = -1
    while q:
        qq = []
        # 新たに#となった地点をqqに格納
        for x, y in q:
            if not visited[x - 1][y]:
                visited[x - 1][y] = True
                qq.append((x - 1, y))
            if not visited[x + 1][y]:
                visited[x + 1][y] = True
                qq.append((x + 1, y))
            if not visited[x][y - 1]:
                visited[x][y - 1] = True
                qq.append((x, y - 1))
            if not visited[x][y + 1]:
                visited[x][y + 1] = True
                qq.append((x, y + 1))
        q = qq
        ans += 1
    print(ans)


if __name__ == "__main__":
    main()

-H, W = list(map(int, input().split())) -INF = 10**18 -q = [] -visited = [[True] * (W + 2)] -visited += [[True] + [x == "#" for x in input().rstrip()] + [True] for _ in range(H)] -visited.append([True] * (W + 2)) -for i in range(1, H + 1): -    for j in range(1, W + 1): -        if visited[i][j]: -            q.append((i, j)) -moves = [(0, 1), (0, -1), (1, 0), (-1, 0)] -ans = -1 -while q: -    qq = [] -    ans += 1 -    for x, y in q: -        if not visited[x - 1][y]: -            visited[x - 1][y] = True -            qq.append((x - 1, y)) -        if not visited[x + 1][y]: -            visited[x + 1][y] = True -            qq.append((x + 1, y)) -        if not visited[x][y - 1]: -            visited[x][y - 1] = True -            qq.append((x, y - 1)) -        if not visited[x][y + 1]: -            visited[x][y + 1] = True -            qq.append((x, y + 1)) -    q = qq -print(ans) + + +def main(): +    H, W = list(map(int, input().split())) +    # 番兵法 (#を外周に設置する) +    visited = [[True] * (W + 2)] +    visited += [ +        [True] + [x == "#" for x in input().rstrip()] + [True] for _ in range(H) +    ] +    visited.append([True] * (W + 2)) +    # #の位置をqに格納 +    q = [] +    for i in range(1, H + 1): +        for j in range(1, W + 1): +            if visited[i][j]: +                q.append((i, j)) +    # dx,dyを使用せずにBFS +    # 定数倍改善 +    ans = -1 +    while q: +        qq = [] +        # 新たに#となった地点をqqに格納 +        for x, y in q: +            if not visited[x - 1][y]: +                visited[x - 1][y] = True +                qq.append((x - 1, y)) +            if not visited[x + 1][y]: +                visited[x + 1][y] = True +                qq.append((x + 1, y)) +            if not visited[x][y - 1]: +                visited[x][y - 1] = True +                qq.append((x, y - 1)) +            if not visited[x][y + 1]: +                visited[x][y + 1] = True +                qq.append((x, y + 1)) +        q = qq +        ans += 1 +    print(ans) + + +if __name__ == "__main__": +    main()