from collections import deque
H, W = map(int, input().split())


if __name__ == '__main__':

    # make graph
    maze = []
    dx = [0, 1, 0, -1]
    dy = [1, 0, -1, 0]

    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] != '#':
                que = deque([[i, j]])
                seen = [[-1 for i in range(W)] for j in range(H)]
                seen[i][j] = 0
                while len(que) != 0:
                    h, w = que[0][0], que[0][1]
                    que.popleft()
                    for k in range(4):
                        if h + dy[k] < 0 or w + dx[k] < 0 or h + dy[k] >= H or w + dx[k] >= W:
                            continue
                        if seen[h + dy[k]][w + dx[k]] != -1 or maze[h + dy[k]][w + dx[k]] == '#':
                            continue
                        seen[h + dy[k]][w + dx[k]] = seen[h][w] + 1
                        que.append([h + dy[k], w + dx[k]])
                if max(max(seen)) > max_path:
                    max_path = max(max(seen))
    print(max_path)