import sys
sys.setrecursionlimit(10**9)

INF = 10**9 + 7


def to_graph(maze):
    H, W = len(maze), len(maze[0])

    g = [[INF] * (H * W) for _ in range(H * W)]

    for i, line in enumerate(maze):
        for j, s in enumerate(line):
            if i == j:
                g[i * W + j][i * W + j] = 0
            if s == '.':
                for neigh in [(-1, 0), (1, 0), (0, 1), (0, -1)]:
                    px, py = i + neigh[0], j + neigh[1]
                    if maze[px][py] == '.':
                        g[i * W + j][px * W + py] = 1

    return g


def main():
    H, W = map(int, input().split())
    maze = []
    maze.append(['#' for _ in range(W + 2)])
    for _ in range(H):
        maze.append(['#'] + list(input()) + ['#'])
    maze.append(['#' for _ in range(W + 2)])

    g = to_graph(maze)

    n = len(g)
    for k in range(n):
        for i in range(n):
            for j in range(n):
                g[i][j] = min(g[i][j], g[i][k] + g[k][j])

    current_max = 0
    for line in g:
        for v in line:
            if v < INF and v > current_max:
                current_max = v

    print(current_max)


if __name__ == '__main__':
    main()
