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
def bfs(start):
    que=deque([start])
    INF=10**9
    dis=[INF]*(w*h)
    dis[start]=0
    move=(1,-1,w,-w)
    while que:
        v=que.popleft()
        for i in move:
            n=v+i
            if s[n]=="#":
                continue
            dv=dis[v]
            dn=dv+1
            if dis[n] <= dv+1:
                continue
            dis[n]=dn
            que.append(n)
    return max(i for i in dis if i<INF)
ans=max(bfs(v) for v in range(h*w) if s[v] != "#")
print(ans)