from collections import deque



def bfs(maze, visited, s, h, w):

  queue = deque(s)

  #　返り値

  va = 0

  while queue:

    y,x = queue.popleft()

    for j, k in ([1, 0], [-1, 0], [0, 1], [0, -1]):

      new_y, new_x = y+j, x+k

      if new_x < 0 or new_x >= w or new_y < 0 or new_y >=h :

        continue

      if maze[new_y][new_x] == "." and visited[new_y][new_x] == -1:

        #　移動回数の計算

        visited[new_y][new_x] = visited[y][x] + 1

        va = max(va,visited[new_y][new_x])

        queue.append([new_y, new_x])

  return va

############



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



maze = [['' for j in range(w)] for i in range(h)]

for i in range(h) :

  m1 = eval(input())

  for j in range(w) :

    maze[i][j] = m1[j]



visited = [[-1]*(w) for _ in range(h)]

ans = []

s = []

s_append = s.append

for sy in range(h) :

  for sx in range(w):

    if maze[sy][sx] == '#' :

      s_append([sy,sx])

      maze[sy][sx] = '.'

      visited[sy][sx] = 0



print((bfs(maze, visited, s, h, w)))
from collections import deque



def bfs(maze, visited, s, h, w):

  queue = deque(s)

  #　返り値

  va = 0

  while queue:

    y,x = queue.popleft()

    for j, k in ([1, 0], [-1, 0], [0, 1], [0, -1]):

      new_y, new_x = y+j, x+k

      if new_x < 0 or new_x >= w or new_y < 0 or new_y >=h :

        continue

      if maze[new_y][new_x] == "." and visited[new_y][new_x] == -1:

        #　移動回数の計算

        visited[new_y][new_x] = visited[y][x] + 1

        va = max(va,visited[new_y][new_x])

        queue.append([new_y, new_x])

  return va

############



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



maze = [['.' for j in range(w)] for i in range(h)]

visited = [[-1]*(w) for _ in range(h)]

s = []

s_append = s.append

for i in range(h) :

  m1 = eval(input())

  for j in range(w) :

    if m1[j] == '#' :

      s_append([i,j])

      visited[i][j] = 0



print((bfs(maze, visited, s, h, w)))
from collections import deque


def bfs(maze, visited, s, h, w):
    queue = deque(s)
    # 　返り値
    va = 0
    while queue:
        y, x = queue.popleft()
        for j, k in ([1, 0], [-1, 0], [0, 1], [0, -1]):
            new_y, new_x = y + j, x + k
            if new_x < 0 or new_x >= w or new_y < 0 or new_y >= h:
                continue
            if maze[new_y][new_x] == "." and visited[new_y][new_x] == -1:
                # 　移動回数の計算
                visited[new_y][new_x] = visited[y][x] + 1
                va = max(va, visited[new_y][new_x])
                queue.append([new_y, new_x])
    return va


############
h, w = list(map(int, input().split()))
maze = [["" for j in range(w)] for i in range(h)]
for i in range(h):
    m1 = eval(input())
    for j in range(w):
        maze[i][j] = m1[j]
visited = [[-1] * (w) for _ in range(h)]
ans = []
s = []
s_append = s.append
for sy in range(h):
    for sx in range(w):
        if maze[sy][sx] == "#":
            s_append([sy, sx])
            maze[sy][sx] = "."
            visited[sy][sx] = 0
print((bfs(maze, visited, s, h, w)))

from collections import deque


def bfs(maze, visited, s, h, w):
    queue = deque(s)
    # 　返り値
    va = 0
    while queue:
        y, x = queue.popleft()
        for j, k in ([1, 0], [-1, 0], [0, 1], [0, -1]):
            new_y, new_x = y + j, x + k
            if new_x < 0 or new_x >= w or new_y < 0 or new_y >= h:
                continue
            if maze[new_y][new_x] == "." and visited[new_y][new_x] == -1:
                # 　移動回数の計算
                visited[new_y][new_x] = visited[y][x] + 1
                va = max(va, visited[new_y][new_x])
                queue.append([new_y, new_x])
    return va


############
h, w = list(map(int, input().split()))
maze = [["." for j in range(w)] for i in range(h)]
visited = [[-1] * (w) for _ in range(h)]
s = []
s_append = s.append
for i in range(h):
    m1 = eval(input())
    for j in range(w):
        if m1[j] == "#":
            s_append([i, j])
            visited[i][j] = 0
print((bfs(maze, visited, s, h, w)))

-maze = [["" for j in range(w)] for i in range(h)] +maze = [["." for j in range(w)] for i in range(h)] +visited = [[-1] * (w) for _ in range(h)] +s = [] +s_append = s.append -        maze[i][j] = m1[j] -visited = [[-1] * (w) for _ in range(h)] -ans = [] -s = [] -s_append = s.append -for sy in range(h): -    for sx in range(w): -        if maze[sy][sx] == "#": -            s_append([sy, sx]) -            maze[sy][sx] = "." -            visited[sy][sx] = 0 +        if m1[j] == "#": +            s_append([i, j]) +            visited[i][j] = 0