H,W=map(int,input().split())
s=[]
for _ in range(H):
    s.append(list(input()))
def dfs(y,x):
    q=[(y,x)]
    visited=[[-1]*W for _ in range(H)]
    visited[y][x]=0
    while q:
        cy,cx=q.pop(0)
        for dy,dx in ((1,0),(-1,0),(0,-1),(0,1)):
            nx=cx+dx
            ny=cy+dy
            if 0<=ny<H and 0<=nx<W and s[ny][nx]=='.' and visited[ny][nx]==-1:
                visited[ny][nx]=visited[cy][cx]+1
                q.append((ny,nx))
    return max(max(i) for i  in visited)
ans=0
for h in range(H):
    for w in range(W):
        if s[h][w]=='.':
            ans=max(dfs(h,w),ans)
print(ans)