import sys
import copy
sys.setrecursionlimit(9**9)
H,W=map(int,input().split())
M=[list(input()) for _ in range(H)]
N=copy.deepcopy(M)
m=x=y=0
def d(c,P):
    global m,x,y
    Q=[]
    for p in P:
        h=p[0]
        w=p[1]
        if h!=H-1 and M[h+1][w]=='.':
            M[h+1][w]='#'
            Q.append([h+1,w])
        if h!=0 and M[h-1][w]=='.':
            M[h-1][w]='#'
            Q.append([h-1,w])
        if w!=W-1 and M[h][w+1]=='.':
            M[h][w+1]='#'
            Q.append([h,w+1])
        if w!=0 and M[h][w-1]=='.':
            M[h][w-1]='#'
            Q.append([h,w-1])
    if len(Q)!=0:
      c+=1
      return d(c,Q)
    else:
        m=c
        x=P[0][0]
        y=P[0][1]
f=False
for i in range(H):
    for j in range(W):
        if M[i][j]=='.':
            M[i][j]='#'
            d(0,[[i,j]])
            f=True
            break
    if f:break
M=N
m=0
M[x][y]='#'
d(0,[[x,y]])
print(m)