from collections import deque

h, w = map(int, (input().split()))
maze = ['#' * (w + 2)] + ['#{}#'.format(input()) for i in range(h)] + ['#' * (w + 2)]
directions = [[0, -1], [-1, 0], [1, 0], [0, 1]]
queue = deque()
answer = 0

for start_x in range(1, h + 1):
    for start_y in range(1, w + 1):
        if maze[start_x][start_y] == '.':
            distance = [[0] * (w + 2) for i in range(h + 2)]
            queue.append([start_x, start_y])
            while queue:
                x, y = queue.popleft()
                for direction in directions:
                    next_x, next_y = x + direction[0], y + direction[1]
                    if maze[next_x][next_y] == '.' and distance[next_x][next_y] == 0:
                        distance[next_x][next_y] = distance[x][y] + 1
                        queue.append([next_x, next_y])
                        answer = max(answer, distance[next_x][next_y])

print(answer)
