from collections import deque

H,W=map(int,input().split())
H+=2
W+=2
s="#"*W
for _ in range(H-2):
    s+="#"+input()+"#"
s+="#"*W

answer=[]

for i in range(W*H):
    if s[i]=="#":
        continue
    dist=[-1]*(W*H)
    q=deque([i])
    dist[i]=0
    while len(q)>0:
        x=q.popleft()
        for j in [-1,1,W,-W]:
            if s[x+j]=="." and dist[x+j]==-1:
                q.append(x+j)
                dist[x+j]=1+dist[x]
    answer.append(max(dist))
print(max(answer))
            


