# A - Darker and Darker

from collections import deque



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

B = [[-1] * W for _ in range(H)]



queue = deque([])



for i in range(H):

    A = eval(input())

    for j in range(W):

        if A[j]=='#':

            B[i][j] = 0

            queue.append((i,j))



ans = 0



while queue:

    I,J = queue.popleft()

    for di,dj in ((-1,0),(1,0),(0,-1),(0,1)):

        i,j = I+di,J+dj

        if 0<=i<H and 0<=j<W:

            if B[i][j]<0:

                B[i][j] = B[I][J]+1

                ans = max(ans,B[i][j])

                queue.append((i,j))



print(ans)
import sys

from sys import exit

from collections import deque

from copy import deepcopy

from bisect import bisect_left, bisect_right, insort_left, insort_right

from heapq import heapify, heappop, heappush

from itertools import product, permutations, combinations, combinations_with_replacement

from functools import reduce

from math import gcd, sin, cos, tan, asin, acos, atan, degrees, radians



sys.setrecursionlimit(10**6)

INF = 10**20

eps = 1.0e-20

MOD = 10**9+7



def lcm(x,y):

    return x*y//gcd(x,y)

def lgcd(l):

    return reduce(gcd,l)

def llcm(l):

    return reduce(lcm,l)

def powmod(n,i,mod=MOD):

    return pow(n,mod-1+i,mod) if i<0 else pow(n,i,mod)

def div2(x):

    return x.bit_length()

def div10(x):

    return len(str(x))-(x==0)

def intput():

    return int(input())

def mint():

    return map(int,input().split())

def lint():

    return list(map(int,input().split()))

def ilint():

    return int(input()), list(map(int,input().split()))

def judge(x, l=['Yes', 'No']):

    print(l[0] if x else l[1])

def lprint(l, sep='\n'):

    for x in l:

        print(x, end=sep)

def ston(c, c0='a'):

    return ord(c)-ord(c0)

def ntos(x, c0='a'):

    return chr(x+ord(c0))

class counter(dict):

    def __init__(self, *args):

        super().__init__(args)

    def add(self,x,d=1):

        self.setdefault(x,0)

        self[x] += d

    def list(self):

        l = []

        for k in self:

            l.extend([k]*self[k])

        return l

class comb():

    def __init__(self, n, mod=None):

        self.l = [1]

        self.n = n

        self.mod = mod

    def get(self,k):

        l,n,mod = self.l, self.n, self.mod

        k = n-k if k>n//2 else k

        while len(l)<=k:

            i = len(l)

            l.append(l[i-1]*(n+1-i)//i if mod==None else (l[i-1]*(n+1-i)*powmod(i,-1,mod))%mod)

        return l[k]

def pf(x,mode='counter'):

    C = counter()

    p = 2

    while x>1:

        k = 0

        while x%p==0:

            x //= p

            k += 1

        if k>0:

            C.add(p,k)

        p = p+2-(p==2) if p*p<x else x

    if mode=='counter':

        return C

    S = set([1])

    for k in C:

        T = deepcopy(S)

        for x in T:

            for i in range(1,C[k]+1):

                S.add(x*(k**i))

    if mode=='set':

        return S

    if mode=='list':

        return sorted(list(S))



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



H,W=mint()

A=[input() for _ in range(H)]

C=[[0]*W for _ in range(H)]

for i,j in product(range(H),range(W)):

    if A[i][j]=='.':

        C[i][j]=INF

for i,j in product(range(H),range(1,W)):

    C[i][j] = min(C[i][j],C[i][j-1]+1)

for i,j in product(range(1,H),range(W)):

    C[i][j] = min(C[i][j],C[i-1][j]+1)

for i,j in product(range(H),range(W-2,-1,-1)):

    C[i][j] = min(C[i][j],C[i][j+1]+1)

for i,j in product(range(H-2,-1,-1),range(W)):

    C[i][j] = min(C[i][j],C[i+1][j]+1)

print(max([max(c) for c in C]))

# A - Darker and Darker
from collections import deque

H, W = list(map(int, input().split()))
B = [[-1] * W for _ in range(H)]
queue = deque([])
for i in range(H):
    A = eval(input())
    for j in range(W):
        if A[j] == "#":
            B[i][j] = 0
            queue.append((i, j))
ans = 0
while queue:
    I, J = queue.popleft()
    for di, dj in ((-1, 0), (1, 0), (0, -1), (0, 1)):
        i, j = I + di, J + dj
        if 0 <= i < H and 0 <= j < W:
            if B[i][j] < 0:
                B[i][j] = B[I][J] + 1
                ans = max(ans, B[i][j])
                queue.append((i, j))
print(ans)

import sys
from sys import exit
from collections import deque
from copy import deepcopy
from bisect import bisect_left, bisect_right, insort_left, insort_right
from heapq import heapify, heappop, heappush
from itertools import product, permutations, combinations, combinations_with_replacement
from functools import reduce
from math import gcd, sin, cos, tan, asin, acos, atan, degrees, radians

sys.setrecursionlimit(10**6)
INF = 10**20
eps = 1.0e-20
MOD = 10**9 + 7


def lcm(x, y):
    return x * y // gcd(x, y)


def lgcd(l):
    return reduce(gcd, l)


def llcm(l):
    return reduce(lcm, l)


def powmod(n, i, mod=MOD):
    return pow(n, mod - 1 + i, mod) if i < 0 else pow(n, i, mod)


def div2(x):
    return x.bit_length()


def div10(x):
    return len(str(x)) - (x == 0)


def intput():
    return int(input())


def mint():
    return map(int, input().split())


def lint():
    return list(map(int, input().split()))


def ilint():
    return int(input()), list(map(int, input().split()))


def judge(x, l=["Yes", "No"]):
    print(l[0] if x else l[1])


def lprint(l, sep="\n"):
    for x in l:
        print(x, end=sep)


def ston(c, c0="a"):
    return ord(c) - ord(c0)


def ntos(x, c0="a"):
    return chr(x + ord(c0))


class counter(dict):
    def __init__(self, *args):
        super().__init__(args)

    def add(self, x, d=1):
        self.setdefault(x, 0)
        self[x] += d

    def list(self):
        l = []
        for k in self:
            l.extend([k] * self[k])
        return l


class comb:
    def __init__(self, n, mod=None):
        self.l = [1]
        self.n = n
        self.mod = mod

    def get(self, k):
        l, n, mod = self.l, self.n, self.mod
        k = n - k if k > n // 2 else k
        while len(l) <= k:
            i = len(l)
            l.append(
                l[i - 1] * (n + 1 - i) // i
                if mod == None
                else (l[i - 1] * (n + 1 - i) * powmod(i, -1, mod)) % mod
            )
        return l[k]


def pf(x, mode="counter"):
    C = counter()
    p = 2
    while x > 1:
        k = 0
        while x % p == 0:
            x //= p
            k += 1
        if k > 0:
            C.add(p, k)
        p = p + 2 - (p == 2) if p * p < x else x
    if mode == "counter":
        return C
    S = set([1])
    for k in C:
        T = deepcopy(S)
        for x in T:
            for i in range(1, C[k] + 1):
                S.add(x * (k**i))
    if mode == "set":
        return S
    if mode == "list":
        return sorted(list(S))


######################################################
H, W = mint()
A = [input() for _ in range(H)]
C = [[0] * W for _ in range(H)]
for i, j in product(range(H), range(W)):
    if A[i][j] == ".":
        C[i][j] = INF
for i, j in product(range(H), range(1, W)):
    C[i][j] = min(C[i][j], C[i][j - 1] + 1)
for i, j in product(range(1, H), range(W)):
    C[i][j] = min(C[i][j], C[i - 1][j] + 1)
for i, j in product(range(H), range(W - 2, -1, -1)):
    C[i][j] = min(C[i][j], C[i][j + 1] + 1)
for i, j in product(range(H - 2, -1, -1), range(W)):
    C[i][j] = min(C[i][j], C[i + 1][j] + 1)
print(max([max(c) for c in C]))

-# A - Darker and Darker +import sys +from sys import exit +from copy import deepcopy +from bisect import bisect_left, bisect_right, insort_left, insort_right +from heapq import heapify, heappop, heappush +from itertools import product, permutations, combinations, combinations_with_replacement +from functools import reduce +from math import gcd, sin, cos, tan, asin, acos, atan, degrees, radians -H, W = list(map(int, input().split())) -B = [[-1] * W for _ in range(H)] -queue = deque([]) -for i in range(H): -    A = eval(input()) -    for j in range(W): -        if A[j] == "#": -            B[i][j] = 0 -            queue.append((i, j)) -ans = 0 -while queue: -    I, J = queue.popleft() -    for di, dj in ((-1, 0), (1, 0), (0, -1), (0, 1)): -        i, j = I + di, J + dj -        if 0 <= i < H and 0 <= j < W: -            if B[i][j] < 0: -                B[i][j] = B[I][J] + 1 -                ans = max(ans, B[i][j]) -                queue.append((i, j)) -print(ans) +sys.setrecursionlimit(10**6) +INF = 10**20 +eps = 1.0e-20 +MOD = 10**9 + 7 + + +def lcm(x, y): +    return x * y // gcd(x, y) + + +def lgcd(l): +    return reduce(gcd, l) + + +def llcm(l): +    return reduce(lcm, l) + + +def powmod(n, i, mod=MOD): +    return pow(n, mod - 1 + i, mod) if i < 0 else pow(n, i, mod) + + +def div2(x): +    return x.bit_length() + + +def div10(x): +    return len(str(x)) - (x == 0) + + +def intput(): +    return int(input()) + + +def mint(): +    return map(int, input().split()) + + +def lint(): +    return list(map(int, input().split())) + + +def ilint(): +    return int(input()), list(map(int, input().split())) + + +def judge(x, l=["Yes", "No"]): +    print(l[0] if x else l[1]) + + +def lprint(l, sep="\n"): +    for x in l: +        print(x, end=sep) + + +def ston(c, c0="a"): +    return ord(c) - ord(c0) + + +def ntos(x, c0="a"): +    return chr(x + ord(c0)) + + +class counter(dict): +    def __init__(self, *args): +        super().__init__(args) + +    def add(self, x, d=1): +        self.setdefault(x, 0) +        self[x] += d + +    def list(self): +        l = [] +        for k in self: +            l.extend([k] * self[k]) +        return l + + +class comb: +    def __init__(self, n, mod=None): +        self.l = [1] +        self.n = n +        self.mod = mod + +    def get(self, k): +        l, n, mod = self.l, self.n, self.mod +        k = n - k if k > n // 2 else k +        while len(l) <= k: +            i = len(l) +            l.append( +                l[i - 1] * (n + 1 - i) // i +                if mod == None +                else (l[i - 1] * (n + 1 - i) * powmod(i, -1, mod)) % mod +            ) +        return l[k] + + +def pf(x, mode="counter"): +    C = counter() +    p = 2 +    while x > 1: +        k = 0 +        while x % p == 0: +            x //= p +            k += 1 +        if k > 0: +            C.add(p, k) +        p = p + 2 - (p == 2) if p * p < x else x +    if mode == "counter": +        return C +    S = set([1]) +    for k in C: +        T = deepcopy(S) +        for x in T: +            for i in range(1, C[k] + 1): +                S.add(x * (k**i)) +    if mode == "set": +        return S +    if mode == "list": +        return sorted(list(S)) + + +###################################################### +H, W = mint() +A = [input() for _ in range(H)] +C = [[0] * W for _ in range(H)] +for i, j in product(range(H), range(W)): +    if A[i][j] == ".": +        C[i][j] = INF +for i, j in product(range(H), range(1, W)): +    C[i][j] = min(C[i][j], C[i][j - 1] + 1) +for i, j in product(range(1, H), range(W)): +    C[i][j] = min(C[i][j], C[i - 1][j] + 1) +for i, j in product(range(H), range(W - 2, -1, -1)): +    C[i][j] = min(C[i][j], C[i][j + 1] + 1) +for i, j in product(range(H - 2, -1, -1), range(W)): +    C[i][j] = min(C[i][j], C[i + 1][j] + 1) +print(max([max(c) for c in C]))