
H,W=map(int, input().split())
d = [ [ 100000 for _ in range(W+2)] for _ in range(H+2)]
S = []
S.append('#' * (W+2))
for i in range(H):
    S.append('#'+ input() + '#')
S.append('#' * (W+2))

def SUB(x,y,n):
    d[y][x] = n
    if (S[y-1][x] == '.') and (d[y-1][x] > n+1): SUB(x,y-1,n+1)
    if (S[y][x-1] == '.') and (d[y][x-1] > n+1): SUB(x-1,y,n+1)
    if (S[y+1][x] == '.') and (d[y+1][x] > n+1): SUB(x,y+1,n+1)
    if (S[y][x+1] == '.') and (d[y][x+1] > n+1): SUB(x+1,y,n+1)

dmax = 0
for y in range(1,H+1):
    for x in range(1,W+1):
        if S[y][x] == '.':
            for iy in range(1,H+1):
                for ix in range(1,W+1):
                    d[iy][ix] = 100000
            SUB(x,y,0)
            for iy in range(1,H+1):
                for ix in range(1,W+1):
                    if d[iy][ix] != 100000:
                        if dmax < d[iy][ix]:
                            dmax = d[iy][ix]
print(dmax)



