from collections import deque
from itertools import combinations

h, w = map(int, input().split())
s = [list(input()) for _ in range(h)]
directions = ((-1, 0), (1, 0), (0, -1), (0, 1))
d = {(x, y): [] for x in range(h) for y in range(w)}

for x in range(h):
    for y in range(w):
        for dx, dy in directions:
            nx, ny = x + dx, y + dy
            if 0 <= nx < h and 0 <= ny < w:
                if s[nx][ny] == '.':
                    d[(x, y)].append((nx, ny))

node = {k: d[k] for k in d if len(d[k])}
ans = 0
for (start, goal) in combinations(node, 2):
    queue = deque([(start, 0)])
    closed = {}
    while len(queue):
        pos, dist = queue.popleft()
        closed[pos] = dist
        if pos == goal:
            ans = max(dist, ans)
            break
        for neighbor in node[pos]:
            if neighbor not in closed:
                queue.append((neighbor, dist + 1))

print(ans)