import queue

H,W=map(int,input().split())
S=[[] for _ in range(H)]

dx=[0,0,-1,1]
dy=[-1,1,0,0]

for i in range(H):
    S[i]=input()

def bfs(i,j):
    max_d=0
    q=queue.Queue()
    q.put((i,j))
    d=[[0]*W for _ in range(H)]
    while not q.empty():
        loc=q.get()
        for k in range(len(dx)):
            x=loc[1]+dx[k]
            y=loc[0]+dy[k]
            if x>=0 and x<W and y>=0 and y<H:
                if S[y][x]==".":
                    if d[y][x]==0:
                        q.put((y,x))
                        d[y][x]=d[loc[0]][loc[1]]+1
                        max_d=max(max_d,d[y][x])
    return max_d

ans=0
for i in range(H):
    for j in range(W):
        ans=max(bfs(i,j),ans)
        
print(ans)