from collections import deque
H,W=map(int,input().split())
M=[list(input()) for _ in range(H)]

def bfs(i,j,d):
    d_max=0
    used=[[False for j in range(W)] for i in range(H)]
    Q=deque()
    Q.append((i,j,d))
    used[i][j]=True
    while Q:
        i,j,d=Q.popleft()
        for ni,nj in ((i+1,j),(i-1,j),(i,j+1),(i,j-1)):
            if ni<0 or nj<0 or ni>=H or nj>=W:
                continue
            if M[ni][nj]=='.' and not used[ni][nj]:
                d_max=max(d_max,d+1)
                used[ni][nj]=True
                Q.append((ni,nj,d+1))
    return d_max

ans=0
for i in range(H):
    for j in range(W):
        if M[i][j]=='.':
            ans=max(ans,bfs(i,j,0))

print(ans)
