H, W = map(int, input().split())


def dfs(g, h, w, s, step):

    s[h][w] = step
    dx = [0, 1, 0, -1]
    dy = [1, 0, -1, 0]

    for i in range(4):
        next_h, next_w = h + dy[i], w + dx[i]
        # boundary
        if next_h < 0 or next_w < 0 or next_h >= H or next_w >= W:
            continue
        if g[next_h][next_w] == '#':
            continue
        if s[next_h][next_w] is not False:
            if s[next_h][next_w] <= step + 1:
                continue
        dfs(g, next_h, next_w, s, step + 1)


if __name__ == '__main__':

    # make graph
    maze = []

    for i in range(H):
        line = input()
        maze.append(line)

    max_path = 0
    for i in range(H):
        for j in range(W):
            if maze[i][j] != '#':
                seen = [[False for i in range(W)] for j in range(H)]
                dfs(maze, i, j, seen, 0)
                if max(max(seen)) > max_path:
                    max_path = max(max(seen))

    print(max_path)