H, W = map(int, input().split())
S = [0] * H
for h in range(H):
    S[h] = input()

max_count = 0

import itertools

for ys, xs in itertools.product(range(H), range(W)):
    for yg, xg in itertools.product(range(H), range(W)):
        if (ys, xs) == (yg, xg):
            continue
        if S[ys][xs] == '#' or S[yg][xg] == '#':
            continue

        n = [(ys, xs)]
        route = {n[0]: 0}
        p = [[1, 0], [0, 1], [-1, 0], [0, -1]]
        count = 1
        while (yg, xg) not in route and count != 500:
            n2 = []
            for i in n:
                for j in p:
                    np = (i[0] + j[0], i[1] + j[1])


                    if np[0] >= H or np[1] >= W or np[0] < 0 or np[1] < 0:
                        continue
                    if S[np[0]][np[1]] == '.' and route.get(np, -1) == -1:
                        n2.append(np)
                        route[np] = count
            n=n2
            count+=1
        if (yg, xg) in route:
            max_count = max(max_count, route[(yg, xg)])

print(max_count)