def main():

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

    a = []

    for i in range(h):

        a.append(eval(input()))

 

    used = [True]*(h*w)

 

    p = []

    for i in range(h):

        for j in range(w):

            if a[i][j] == '#':

                p.append(i*w+j)

                used[i*w+j] = False

 

 

    

    res = 0

    while p:

        tank = []

        for e in p:

            if (e-w)>=0 and used[e-w]:

                tank.append(e-w)

                used[e-w] = False

            if e%w-1 >= 0 and used[e-1]:

                tank.append(e-1)

                used[e-1] = False

            if e+w<w*h and used[e+w]:

                tank.append(e+w)

                used[e+w] = False

            if e%w+1<w and used[e+1]:

                tank.append(e+1)

                used[e+1] =  False

        p = tank

        res += 1

    print((res-1))



if __name__ == '__main__':

    main()
def main():

  num_r,num_c = list(map(int,input().split()))

  field = [eval(input()) for i in range(num_r)]

  q = []

  seen = [0]*(num_c*num_r)

  count = 0

 

  for i in range(num_r):

    for j in range(num_c):

      if field[i][j] == "#":

        seen[i*num_c+j] = 1

        q.append([i,j])

      

  while q:

    tank = []

    for i in q:

      r = i[0]

      c = i[1]

      if (0<=r-1) and (seen[(r-1)*num_c+c] == 0):

        tank.append([r-1,c])

        seen[(r-1)*num_c+c] = 1

      if (r+1<num_r) and (seen[(r+1)*num_c+c] == 0):

        tank.append([r+1,c])

        seen[(r+1)*num_c+c] = 1

      if (0<=c-1) and (seen[r*num_c+(c-1)] == 0):

        tank.append([r,c-1])

        seen[r*num_c+(c-1)] = 1

      if (c+1<num_c) and (seen[r*num_c+(c+1)] == 0):

        tank.append([r,c+1])

        seen[r*num_c+(c+1)] = 1

 

    count = count + 1

    q = tank

 

  print((count-1))

  

if __name__ == '__main__':

    main()
def main():
    h, w = list(map(int, input().split()))
    a = []
    for i in range(h):
        a.append(eval(input()))
    used = [True] * (h * w)
    p = []
    for i in range(h):
        for j in range(w):
            if a[i][j] == "#":
                p.append(i * w + j)
                used[i * w + j] = False
    res = 0
    while p:
        tank = []
        for e in p:
            if (e - w) >= 0 and used[e - w]:
                tank.append(e - w)
                used[e - w] = False
            if e % w - 1 >= 0 and used[e - 1]:
                tank.append(e - 1)
                used[e - 1] = False
            if e + w < w * h and used[e + w]:
                tank.append(e + w)
                used[e + w] = False
            if e % w + 1 < w and used[e + 1]:
                tank.append(e + 1)
                used[e + 1] = False
        p = tank
        res += 1
    print((res - 1))


if __name__ == "__main__":
    main()

def main():
    num_r, num_c = list(map(int, input().split()))
    field = [eval(input()) for i in range(num_r)]
    q = []
    seen = [0] * (num_c * num_r)
    count = 0
    for i in range(num_r):
        for j in range(num_c):
            if field[i][j] == "#":
                seen[i * num_c + j] = 1
                q.append([i, j])
    while q:
        tank = []
        for i in q:
            r = i[0]
            c = i[1]
            if (0 <= r - 1) and (seen[(r - 1) * num_c + c] == 0):
                tank.append([r - 1, c])
                seen[(r - 1) * num_c + c] = 1
            if (r + 1 < num_r) and (seen[(r + 1) * num_c + c] == 0):
                tank.append([r + 1, c])
                seen[(r + 1) * num_c + c] = 1
            if (0 <= c - 1) and (seen[r * num_c + (c - 1)] == 0):
                tank.append([r, c - 1])
                seen[r * num_c + (c - 1)] = 1
            if (c + 1 < num_c) and (seen[r * num_c + (c + 1)] == 0):
                tank.append([r, c + 1])
                seen[r * num_c + (c + 1)] = 1
        count = count + 1
        q = tank
    print((count - 1))


if __name__ == "__main__":
    main()

-    h, w = list(map(int, input().split())) -    a = [] -    for i in range(h): -        a.append(eval(input())) -    used = [True] * (h * w) -    p = [] -    for i in range(h): -        for j in range(w): -            if a[i][j] == "#": -                p.append(i * w + j) -                used[i * w + j] = False -    res = 0 -    while p: +    num_r, num_c = list(map(int, input().split())) +    field = [eval(input()) for i in range(num_r)] +    q = [] +    seen = [0] * (num_c * num_r) +    count = 0 +    for i in range(num_r): +        for j in range(num_c): +            if field[i][j] == "#": +                seen[i * num_c + j] = 1 +                q.append([i, j]) +    while q: -        for e in p: -            if (e - w) >= 0 and used[e - w]: -                tank.append(e - w) -                used[e - w] = False -            if e % w - 1 >= 0 and used[e - 1]: -                tank.append(e - 1) -                used[e - 1] = False -            if e + w < w * h and used[e + w]: -                tank.append(e + w) -                used[e + w] = False -            if e % w + 1 < w and used[e + 1]: -                tank.append(e + 1) -                used[e + 1] = False -        p = tank -        res += 1 -    print((res - 1)) +        for i in q: +            r = i[0] +            c = i[1] +            if (0 <= r - 1) and (seen[(r - 1) * num_c + c] == 0): +                tank.append([r - 1, c]) +                seen[(r - 1) * num_c + c] = 1 +            if (r + 1 < num_r) and (seen[(r + 1) * num_c + c] == 0): +                tank.append([r + 1, c]) +                seen[(r + 1) * num_c + c] = 1 +            if (0 <= c - 1) and (seen[r * num_c + (c - 1)] == 0): +                tank.append([r, c - 1]) +                seen[r * num_c + (c - 1)] = 1 +            if (c + 1 < num_c) and (seen[r * num_c + (c + 1)] == 0): +                tank.append([r, c + 1]) +                seen[r * num_c + (c + 1)] = 1 +        count = count + 1 +        q = tank +    print((count - 1))