from collections import deque

def dfs(maze, visited, sh, sw):
    stack = deque([[sh, sw]])
    visited[sh][sw] = 1
    while stack:
        h, w = stack.pop()
        for j, k in ([1, 0], [-1, 0], [0, 1], [0, -1]):
            new_h, new_w = h+j, w+k
            if new_h < 0 or new_h >= H or \
               new_w < 0 or new_w >= W:
                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])
            elif maze[new_h][new_w] != "#":
                if visited[h][w] + 1 < visited[new_h][new_w]:
                    visited[new_h][new_w] = visited[h][w] + 1
                    stack.append([new_h,new_w])

    return visited

H, W = map(int, input().split())
maze = [input() for _ in range(H)]
ans = 0
for i in range(H):
    for j in range(W):
        visited = [[0]*W for _ in range(H)]
        sh = i
        sw = j
        dfs(maze, visited, sh, sw)
        MAX = 0
        for v in visited:
            for e in v:
                MAX = max(MAX,e)
        ans = max(MAX-1,ans)
print(ans)
