### BUGGY CODE ###

h,w = map(int,input().split())
data_t = []
for _ in range(h):
    list_ = str(input())
    data_t.append(list_)

""" data preparation """
data = []
datamaplt = []
datamaprt = []
datamaplb = []
datamaprb = []

dummylist = []
for _ in range(w+2):
    dummylist.append(10**9)

dummylist0 = []
dummylist0.append(10**9)
for _ in range(w):
    dummylist0.append(0)
dummylist0.append(10**9)

data.append(list(dummylist))
datamaplt.append(list(dummylist))
datamaprt.append(list(dummylist))
datamaplb.append(list(dummylist))
datamaprb.append(list(dummylist))

for i in range(h):
    #data.append([])
    #data[i+1].append(10**9)
    data.append(list(dummylist0))
    
    datamaplt.append(list(dummylist0))
    datamaprt.append(list(dummylist0))
    datamaplb.append(list(dummylist0))
    datamaprb.append(list(dummylist0))
    
    """for  j in range(w):
        if data_t[i][j] == "#":
            data[1+i].append(1)
        else:
            data[1+i].append(0)
            
    data[i+1].append(10**9)"""
    
    for  j in range(w):
        if data_t[i][j] == "#":
            data[1+i][j+1] = 1

data.append(list(dummylist))
datamaplt.append(list(dummylist))
datamaprt.append(list(dummylist))
datamaplb.append(list(dummylist))
datamaprb.append(list(dummylist))
""" data preparation """




for i in range(h):
    for  j in range(w):
        ii = i+1
        jj = j+1
        if data[ii][jj] == 0:
            if j == 0:
                beflt_fromleft = 10**9
                
            fromtop = datamaplt[ii-1][jj]+1
            fromleft = beflt_fromleft+1
            
            min_ = min(fromtop,fromleft)
            datamaplt[ii][jj] = min_
            beflt_fromleft = min_
        else:
            beflt_fromleft = 0
            

    for  j in range(w-1,-1,-1):
        ii = i+1
        jj = j+1
        if data[ii][jj] == 0:
            if j == w-1:
                befrt_fromright = 10**9
            fromtop = datamaprt[ii-1][jj]+1
            fromright = befrt_fromright+1
            
            min_ = min(fromtop,fromright)
            datamaprt[ii][jj] = min_
            befrt_fromright = min_
        else:
            befrt_fromright = 0

for i in range(h-1,-1,-1):
    for  j in range(w):
        ii = i+1
        jj = j+1
        if data[ii][jj] == 0:
            if j == 0:
                beflb_fromleft = 10**9
            frombottom = datamaplb[ii+1][jj]+1
            fromleft = beflb_fromleft+1
            min_ = min(frombottom,fromleft)
            datamaplb[ii][jj] = min_
            beflb_fromleft = min_
        else:
            beflb_fromleft = 0

    for  j in range(w-1,-1,-1):
        ii = i+1
        jj = j+1
        if data[ii][jj] == 0:
            if j == w-1:
                befrb_fromright= 10**9
            frombottom = datamaprb[ii+1][jj]+1
            fromright = befrb_fromright+1
            min_= min(fromright,frombottom)
            datamaprb[ii][jj] = min_
        else:
            befrb_fromright= 0
            
ans = 0  
for i in range(h):
    for  j in range(w):
        ii = i+1
        jj = j+1
        min_temp = min(datamaplt[ii][jj],datamaprt[ii][jj],datamaplb[ii][jj],datamaprb[ii][jj])
        if min_temp > ans:
            ans =  min_temp
            
print(ans)


### FIXED CODE ###

h,w = map(int,input().split())
data_t = []
for _ in range(h):
    list_ = str(input())
    data_t.append(list_)

""" data preparation """
data = []
datamaplt = []
datamaprt = []
datamaplb = []
datamaprb = []

data.append([])
datamaplt.append([])
datamaprt.append([])
datamaplb.append([])
datamaprb.append([])
for _ in range(w+2):
    data[0].append(10**9)
    datamaplt[0].append(10**9)
    datamaprt[0].append(10**9)
    datamaplb[0].append(10**9)
    datamaprb[0].append(10**9)

for i in range(h):
    data.append([])
    data[i+1].append(10**9)
    datamaplt.append([])
    datamaplt[i+1].append(10**9)
    datamaprt.append([])
    datamaprt[i+1].append(10**9)
    datamaplb.append([])
    datamaplb[i+1].append(10**9)
    datamaprb.append([])
    datamaprb[i+1].append(10**9)
    for  j in range(w):
        if data_t[i][j] == "#":
            data[1+i].append(1)
        else:
            data[1+i].append(0)
        datamaplt[1+i].append(0)
        datamaprt[1+i].append(0)
        datamaplb[1+i].append(0)
        datamaprb[1+i].append(0)
    data[i+1].append(10**9)
    datamaplt[i+1].append(10**9)
    datamaprt[i+1].append(10**9)
    datamaplb[i+1].append(10**9)
    datamaprb[i+1].append(10**9)

data.append([])
datamaplt.append([])
datamaprt.append([])
datamaplb.append([])
datamaprb.append([])
for _ in range(w+2):
    data[h+1].append(10**9)
    datamaplt[h+1].append(10**9)
    datamaprt[h+1].append(10**9)
    datamaplb[h+1].append(10**9)
    datamaprb[h+1].append(10**9)

""" data preparation """




for i in range(h):
    for  j in range(w):
        ii = i+1
        jj = j+1
        if data[ii][jj] == 0:
            fromtop = datamaplt[ii-1][jj]+1
            fromleft = datamaplt[ii][jj-1]+1
            datamaplt[ii][jj] = min(fromtop,fromleft)

    for  j in range(w-1,-1,-1):
        ii = i+1
        jj = j+1
        if data[ii][jj] == 0:
            fromtop = datamaprt[ii-1][jj]+1
            fromright = datamaprt[ii][jj+1]+1
            datamaprt[ii][jj] = min(fromtop,fromright)

for i in range(h-1,-1,-1):
    for  j in range(w):
        ii = i+1
        jj = j+1
        if data[ii][jj] == 0:
            frombottom = datamaplb[ii+1][jj]+1
            fromleft = datamaplb[ii][jj-1]+1
            datamaplb[ii][jj] = min(frombottom,fromleft)

    for  j in range(w-1,-1,-1):
        ii = i+1
        jj = j+1
        if data[ii][jj] == 0:
            frombottom = datamaprb[ii+1][jj]+1
            fromright = datamaprb[ii][jj+1]+1
            datamaprb[ii][jj] = min(fromright,frombottom)
            
ans = 0  
for i in range(h):
    for  j in range(w):
        ii = i+1
        jj = j+1
        min_temp = min(datamaplt[ii][jj],datamaprt[ii][jj],datamaplb[ii][jj],datamaprb[ii][jj])
        if min_temp > ans:
            ans =  min_temp
            
print(ans)