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

max_count = 0

import itertools

s_list = list(itertools.product(range(H), range(W)))
# g_list = list(itertools.product(range(H), range(W)))
s_g_list = list(itertools.combinations(s_list, 2))

for start, goal in itertools.combinations(s_list, 2):
    ys = start[0]
    xs = start[1]
    yg = goal[0]
    xg = goal[1]
    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)