from collections import deque
import copy

H, W = map(int, input().split())
S = [list(input()) for _ in range(H)]
neig = [(1, 0), (0, 1), (-1, 0), (0, -1)]

road = []
for h in range(H):
    for w in range(W):
        if S[h][w] == '.':
            road.append((h, w))

ans = 0
for rh, rw in road:
    SC, q = copy.deepcopy(S), deque([(rh, rw, 0)])
    SC[rh][rw] = 0
    while len(q) > 0:
        h, w, i = q.popleft()
        for nh, nw in neig:
            if 0 <= h - nh < H and 0 <= w - nw < W and SC[h - nh][w - nw] == '.':
                SC[h - nh][w - nw] = i + 1
                ans = max(ans, i + 1)
                q.append([h - nh, w - nw, i + 1])

print(ans)
