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

def dfs(maze,visited, sh, sw):
    a = 0
    stack = deque([[sh, sw]])
    visited[sh][sw] = 0
    while stack:
        h, w = stack.popleft()
        for j, k in ([1, 0], [-1, 0], [0, 1], [0, -1]): #4近傍について探索
            new_h, new_w = h+j, w+k
            if new_h < 0 or new_h >= H or \
               new_w < 0 or new_w >= W: #リスト外でないならelif条件へ
                continue
            elif maze[new_h][new_w] != "#" and \
                visited[new_h][new_w] == 0: #行ったことがないかつ、壁でないなら
                visited[new_h][new_w] = visited[h][w]+1
                stack.append([new_h, new_w])
    a = 0
    for s in range(H):
        for x in range(W):
            a = max(a,visited[s][x])
    return a

ans = 0

for i in range(H):
    for q in range(W):
        visited = [[0]*W for _ in range(H)]
        if lst1[i][q] == ".":
            ans = max(ans,dfs(lst1,visited,i,q))
print(ans)
