from collections import deque

def input_bordered_grid(h, w, wall):
    grid = [[wall] * (w + 2)]
    for _ in range(1, h+1):
        grid.append([wall] + [c for c in input()] + [wall])
    grid.append([wall] * (w + 2))
    return grid

h, w = map(int, input().split())
grid = input_bordered_grid(h, w, '#')

move = [(-1, 0), (1, 0), (0, -1), (0, 1)]

longest = 0
for sy in range(1, h+1):
    for sx in range(1, w+1):
        q = deque()
        visited = set()
        q.append((sy, sx, 0))
        while q:
            y, x, d = q.popleft()
            visited.add((y, x))
            longest = max(longest, d)
            for dy, dx in move:
                yy = y + dy
                xx = x + dx
                if not (yy, xx) in visited and grid[yy][xx] == '.':
                    q.append((yy, xx, d + 1))
print(longest)
