import copy

H,W = [int(i) for i in input().rstrip().split(' ')]
S = [list(input()) for _ in range(H)]
S1 = copy.deepcopy(S)
start = []
for y in range(H):
    b = False
    for x in range(W):
        if S[y][x] == ".":
            start = (y,x)
            #print(start)
            b = True
            break
    if b:
        break

def dd(P,l,M):
    def nexts(y,x,M):
        n = []
        if y > 0 and M[y-1][x] == ".":
            n += [(y-1,x)] # up
        if y < H - 1 and M[y+1][x] == ".":
            n += [(y+1,x)] # down
        if x > 0 and M[y][x-1] == ".":
            n += [(y,x-1)] # left
        if x < W - 1 and M[y][x+1] == ".":
            n += [(y,x+1)]  # right
        return n

    n = []
    for y,x in P:
        #print("dd",l,y,x)
        n += nexts(y,x,M)
    n = list(set(n))

    for y,x in n:
        M[y][x] = "#"

    if n == []:
        return [(l,P[0])]
    else:
        return dd(n,l+1,M)

far = sorted(dd([start], 0, S1),reverse=True)[0]
far2 = sorted(dd([far[1]], 0, S),reverse=True)[0]
print(far2[0])