import copy

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)

H,W = [int(i) for i in input().rstrip().split(' ')]
S = [list(input()) for _ in range(H)]
S1 = copy.deepcopy(S)
mr = 0
for y in range(H):
    b = False
    for x in range(W):
        if S[y][x] == ".":
            S1 = copy.deepcopy(S)
            far = sorted(dd([(y,x)], 0, S1), reverse=True)[0]
            #print(y,x,far)
            if mr < far[0]:
                mr = far[0]
print(mr)