import collections

H,W=map(int,input().split())
S=[input() for i in range(H)]
cl=set()
for sy,sx in [[h,w] for h in range(H) for w in range(W)]:
    if S[sy][sx]!="#":
        for gy,gx in [[h,w] for h in range(H) for w in range(W)]:
            if S[gy][gx]!="#":
                stack=collections.deque([[sy,sx,0]])
                itta=set([sy*100+sx])
                #print(stack)
                while stack:
                    y,x,m=stack.popleft()
                    if y==gy and x==gx:
                        cl.add(m)
                        break
                    lst=[]

                    if y>0:lst.append([-1,0])
                    if y<H-1:lst.append([1,0])
                    if x>0:lst.append([0,-1])
                    if x<W-1:lst.append([0,1])

                    for a,b in lst:
                        Y=y+a
                        X=x+b
                        #print(Y,X)
                        if S[Y][X]=="." and not Y*100+X in itta:
                            stack.append([Y,X,m+1])
print(max(cl))
