from collections import deque

h,w = map(int,input().split())
maze = [input() for _ in range(h)]
check = [[-1]*w for _ in range(h)]

def BFS(maze,check,si,sj):
    queue = deque([[si,sj]])
    check[si][sj] = 0
    while queue:
        x,y = queue.popleft()
        for k,l in ([0,1], [0,-1], [1,0], [-1,0]):
            i2, j2= x+k, y+l
            if i2<0 or i2>=h or j2<0 or j2>=w:
                continue
            if maze[i2][j2] == '.' and check[i2][j2] == -1:
                check[i2][j2] = check[x][y] + 1
                queue.append([i2,j2])
    return max(max(check))

ans = 0
for i in range(h):
    for j in range(w):
        check = [[-1]*w for _ in range(h)]
        if maze[i][j] == '.':
            si , sj = i, j
            ans = max(ans,BFS(maze,check,si,sj))
print(ans)
