from collections import deque
h, w = map(int, input().split())
area = []
h += 2
w += 2
INF = 1000

for i in range(h):
    if i == 0 or i == h-1:
        array = ['#'] * w
    else:
        array = list(input())
        array.insert(0, '#')
        array.append('#')
    area.append(array)

line = []
for i in range(h):
    for j in range(w):
        if area[i][j] == '#':
            line.append(INF)
        else:
            line.append(1)


def bfs(start):
    unsearched_points = deque()
    searched_points = deque()
    distance_matrix = [INF for _ in range(h*w)]
    unsearched_points.append(start)
    distance_matrix[start] = 0
    while len(unsearched_points) > 0:
        current_point = unsearched_points.popleft()
        searched_points.append(current_point)
        for move in (-1, 1, -w, w):
            if line[current_point+move] == 1 and current_point+move not in searched_points:
                unsearched_points.append(current_point+move)
                distance_matrix[current_point+move] = distance_matrix[current_point] + 1
    l = [x for x in distance_matrix if x < INF]
    return max(l)

max_distance = 0
for i in range(len(line)-w):
    if line[i] == INF:
        continue
    else:
        distance = bfs(i)
        if max_distance < distance:
            max_distance = distance

print(max_distance)

