import sys

#import numpy as np

import math

#from fractions import Fraction

#import itertools

from collections import deque

#import heapq

#from fractions  import gcd

input=sys.stdin.readline

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

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

b=deque()

n=[-1]*(h*w)

c=0

for i in range(h):

    for j in range(w):

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

             b.append((i,j))

             n[i*w+j]=0

        else:

            continue

while b:

    z=b.popleft()

    i=z[0]

    j=z[1]

    if i<h-1 and n[(i+1)*w+j]==-1:

      n[(i+1)*w+j]=n[i*w+j]+1

      c=max(c,n[i*w+j]+1)

      b.append(((i+1),j))

      f=True

    if i>0  and n[(i-1)*w+j]==-1:

      n[(i-1)*w+j]=n[i*w+j]+1

      c=max(c,n[i*w+j]+1)

      b.append(((i-1),j))

      f=True

    if j<w-1 and n[i*w+(j+1)]==-1:

      f=True

      n[i*w+(j+1)]=n[i*w+j]+1

      c=max(c,n[i*w+j]+1)

      b.append((i,(j+1)))

    if j>0  and n[i*w+(j-1)]==-1:

      f=True

      n[i*w+(j-1)]=n[i*w+j]+1

      c=max(c,n[i*w+j]+1)

      b.append((i,(j-1)))

   

print(c)

        
import sys

#import numpy as np

import math

#from fractions import Fraction

#import itertools

from collections import deque

#import heapq

#from fractions  import gcd

input=sys.stdin.readline

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

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

b=deque()

n=[-1]*(h*w)

p=((1,0),(-1,0),(0,1),(0,-1))

for x in range(h):

  for y in range(w):

    if a[x][y]=="#":

      b.append((x,y))

      n[x*w+y]=0

while b:

  x,y=b.popleft()

  for idx in p:

    s,t=idx

    if 0<=x+s<h and 0<=y+t<w:

      if n[(x+s)*w+(y+t)]==-1:

        n[(x+s)*w+(y+t)]=n[x*w+y]+1

        b.append((x+s,y+t))

print((max(n)))

import sys

# import numpy as np
import math

# from fractions import Fraction
# import itertools
from collections import deque

# import heapq
# from fractions  import gcd
input = sys.stdin.readline
h, w = list(map(int, input().split()))
a = [list(map(str, eval(input()))) for _ in range(h)]
b = deque()
n = [-1] * (h * w)
c = 0
for i in range(h):
    for j in range(w):
        if a[i][j] == "#":
            b.append((i, j))
            n[i * w + j] = 0
        else:
            continue
while b:
    z = b.popleft()
    i = z[0]
    j = z[1]
    if i < h - 1 and n[(i + 1) * w + j] == -1:
        n[(i + 1) * w + j] = n[i * w + j] + 1
        c = max(c, n[i * w + j] + 1)
        b.append(((i + 1), j))
        f = True
    if i > 0 and n[(i - 1) * w + j] == -1:
        n[(i - 1) * w + j] = n[i * w + j] + 1
        c = max(c, n[i * w + j] + 1)
        b.append(((i - 1), j))
        f = True
    if j < w - 1 and n[i * w + (j + 1)] == -1:
        f = True
        n[i * w + (j + 1)] = n[i * w + j] + 1
        c = max(c, n[i * w + j] + 1)
        b.append((i, (j + 1)))
    if j > 0 and n[i * w + (j - 1)] == -1:
        f = True
        n[i * w + (j - 1)] = n[i * w + j] + 1
        c = max(c, n[i * w + j] + 1)
        b.append((i, (j - 1)))
print(c)

import sys

# import numpy as np
import math

# from fractions import Fraction
# import itertools
from collections import deque

# import heapq
# from fractions  import gcd
input = sys.stdin.readline
h, w = list(map(int, input().split()))
a = [list(map(str, eval(input()))) for _ in range(h)]
b = deque()
n = [-1] * (h * w)
p = ((1, 0), (-1, 0), (0, 1), (0, -1))
for x in range(h):
    for y in range(w):
        if a[x][y] == "#":
            b.append((x, y))
            n[x * w + y] = 0
while b:
    x, y = b.popleft()
    for idx in p:
        s, t = idx
        if 0 <= x + s < h and 0 <= y + t < w:
            if n[(x + s) * w + (y + t)] == -1:
                n[(x + s) * w + (y + t)] = n[x * w + y] + 1
                b.append((x + s, y + t))
print((max(n)))

-c = 0 -for i in range(h): -    for j in range(w): -        if a[i][j] == "#": -            b.append((i, j)) -            n[i * w + j] = 0 -        else: -            continue +p = ((1, 0), (-1, 0), (0, 1), (0, -1)) +for x in range(h): +    for y in range(w): +        if a[x][y] == "#": +            b.append((x, y)) +            n[x * w + y] = 0 -    z = b.popleft() -    i = z[0] -    j = z[1] -    if i < h - 1 and n[(i + 1) * w + j] == -1: -        n[(i + 1) * w + j] = n[i * w + j] + 1 -        c = max(c, n[i * w + j] + 1) -        b.append(((i + 1), j)) -        f = True -    if i > 0 and n[(i - 1) * w + j] == -1: -        n[(i - 1) * w + j] = n[i * w + j] + 1 -        c = max(c, n[i * w + j] + 1) -        b.append(((i - 1), j)) -        f = True -    if j < w - 1 and n[i * w + (j + 1)] == -1: -        f = True -        n[i * w + (j + 1)] = n[i * w + j] + 1 -        c = max(c, n[i * w + j] + 1) -        b.append((i, (j + 1))) -    if j > 0 and n[i * w + (j - 1)] == -1: -        f = True -        n[i * w + (j - 1)] = n[i * w + j] + 1 -        c = max(c, n[i * w + j] + 1) -        b.append((i, (j - 1))) -print(c) +    x, y = b.popleft() +    for idx in p: +        s, t = idx +        if 0 <= x + s < h and 0 <= y + t < w: +            if n[(x + s) * w + (y + t)] == -1: +                n[(x + s) * w + (y + t)] = n[x * w + y] + 1 +                b.append((x + s, y + t)) +print((max(n)))