from collections import deque

def solve(s, start):
    if s[start[0]][start[1]] == "#":
        return -1 
    q = deque([start])
    distance = [[-1] * w for _ in range(h)]
    distance[start[0]][start[1]] = 0

    while q:
        y, x = q.popleft()
        for i, j in ((1, 0), (-1, 0), (0, 1), (0, -1)):
            new_y, new_x = y + i, x + j
            if not(0 <= new_y < h and 0 <= new_x < w): continue
            if s[new_y][new_x] == "#": continue
            if distance[new_y][new_x] == -1:
                distance[new_y][new_x] = distance[y][x] + 1
                q.append([new_y, new_x])

    print(distance)
    return max(map(max, distance))


h, w = map(int, input().split())
s = [input() for _ in range(h)]

ans = 0
for i in range(h):
    for j in range(w):
        ans = max(ans, solve(s, [i, j]))

print(ans)
