H, W = list(map(int,input().split()))
S = ["#"*(W+2)]
for y in range(H):
    S.append("#"+input()+"#")
S.append("#"*(W+2))
ret = 0
for py in range(1,H+1):
    for px in range(1,W+1):
        if S[py][px]=="#":
            continue
        d = [[-1 for x in range(W+2)] for y in range(H+2)]
        d[py][px]=0
        q=[(py,px)]
        while q:
            y1,x1=q.pop(0)
            for dy,dx in ((0,1),(0,-1),(1,0),(-1,0)):
                y2=y1+dy
                x2=x1+dx
                if S[y2][x2]=="#" or d[y2][x2]>=0:
                    continue
                d[y2][x2]=d[y1][x1]+1
                q.append((y2,x2))
        ret = max(ret, max(max(d)))
print(ret)