from collections import deque
inf = 401
H,W=map(int,input().split(' '))
maze=[list(input()) for i in range(H)]
ans = 0
def short_long(a,b):
    q=deque()
    q.append((a,b))
    d=[[inf for i in range(W)] for j in range(H)]
    d[a][b]=0
    tmp = 0
    while q:
        x,y=q.popleft()
        for i,j in [(1,0),(-1,0),(0,1),(0,-1)]:
            nx,ny=x+i,y+j
            if 0<=nx<H and 0<=ny<W and maze[nx][ny]!='#' and d[nx][ny] == inf:
                q.append((nx,ny))
                d[nx][ny]=d[x][y]+1
                tmp = max(d[nx][ny],tmp)
    return tmp
for i in range(H):
    for j in range(W):
        if maze[i][j] =='.':
            ans =max(ans,short_long(i,j))
print(ans)