from collections import deque

H, W = map(int, input().split())
maze = []
for _ in range(H):
    maze.append(list(input()))


def bfs(initial):
    # goal判定はなく、一番遠いところで返す
    frontier = deque()
    frontier.append((initial, None))
    # tuple
    explored = {initial}
    while len(frontier):
        locations = []
        current_node = frontier.popleft()
        current_state = current_node[0]
        x, y = current_state
        if (x + 1 < H) and (maze[x + 1][y] != '#'):
            locations.append((x + 1, y))
        # 上に行けるかの判定
        if (x - 1 >= 0) and (maze[x - 1][y] != '#'):
            locations.append((x - 1, y))
        # 右に行けるかの判定
        if (y + 1 < W) and (maze[x][y + 1] != '#'):
            locations.append((x, y + 1))
        # 左に行けるかの判定
        if (y - 1 >= 0) and (maze[x][y - 1] != '#'):
            locations.append((x, y - 1))
        for child in locations:
            if str(child) in [str(i) for i in explored]:
                continue
            explored.add(child)
            frontier.append((child, current_node))
    return current_node


def node_to_path_count(node):
    counter = 0
    while node[1] is not None:
        counter += 1
        node = node[1]
    return counter


ans = 0
for x in range(H):
    for y in range(W):
        if maze[x][y] == '.':
            solution = bfs((x, y))
            counter = node_to_path_count(solution)
            if ans < counter:
                ans = counter

print(ans)
