from copy import deepcopy


def solve(maze, i, j, h, w, count):
    if maze[i][j] == "#":
        return 0
    else:
        next_search = [(i, j)]
        while not next_search == []:
            now = next_search.pop(0)
            if maze[now[0]][now[1]] == ".":
                maze[now[0]][now[1]] = "#"
                for direction in [(0, 1), (1, 0), (0, -1), (-1, 0)]:
                    search = [direction[0] + now[0], direction[1] + now[1]]
                    if 0 <= search[0] < h and 0 <= search[1] < w and maze[search[0]][search[1]] == ".":
                        count[now[0] + direction[0]][now[1] + direction[1]] = count[now[0]][now[1]] + 1
                        next_search.append((now[0] + direction[0], now[1] + direction[1]))
        return max(max(count))


def main():
    height, width = map(int, input().split(" "))
    maze = []
    answer = 0
    for _ in range(height):
        maze.append(list(input()))
    count = [[0 for _ in range(width)] for _ in range(height)]
    for i in range(height):
        for j in range(width):
            answer = max(answer, solve(deepcopy(maze), i, j, height, width, deepcopy(count)))
    print(answer)


if __name__ == '__main__':
    main()

