import sys
from copy import deepcopy
from collections import deque

h, w = map(int, inputs[0].split())
S = deque(deque(map(lambda x: int(x=='.'), x)) for x in inputs[1:])
S.appendleft(deque([0]*w))
S.append(deque([0]*w))
for row in S:
    row.appendleft(0)
    row.append(0)

max_dist = 0
for y in range(1, h+1):
    for x in range(1, w+1):
        if S[y][x]:
            maze = deepcopy(S)
            queue = deque([(x, y, 0)])
            while queue:
                x, y, d = queue.popleft()
                d += 1
                maze[y][x] = 0
                for dx, dy in zip([0, 1, 0, -1], [-1, 0, 1, 0]):
                    if maze[y+dy][x+dx]:
                        queue.append((x+dx, y+dy, d))
                        maze[y+dy][x+dx] = 0
                        max_dist = max(max_dist, d)
print(max_dist)