import queue

H,W=map(int,input().split())
c=["#"*(W+2)]+["#"+input()+"#" for _ in range(H)]+["#"*(W+2)]

ans=0
for i in range(1,H+1):
    for g in range(1,W+1):
        MAX=0
        s=(i,g)
        dist=[[-1]*(W+2) for _ in range(H+2)]
        que=queue.Queue()
        que.put(s)
        dist[s[0]][s[1]]=0

        while not que.empty():
            h,w=que.get()
            direction=[(0,-1),(0,1),(1,0),(-1,0)]
            for y,x in direction:
                if c[h+y][w+x]=="." and dist[h+y][w+x]==-1:
                    que.put((h+y,w+x))
                    dist[h+y][w+x]=dist[h][w]+1
                    MAX=max(MAX,dist[h+y][w+x])
        ans=max(MAX,ans)
print(ans)