from collections import deque
H, W = list(map(int, input().split()))
S = []
for _ in range(H):
    S.append(list(input()))

mv = {(1, 0), (-1, 0), (0, 1), (0, -1)}


def BFS(St, G):
    stk = deque([St+[0]])
    seen = [[False]*W for _ in range(H)]
    while len(stk) > 0:
        l = stk.pop()
        i = l[0]
        j = l[1]
        ct = l[2]
        seen[i][j] = True
        if i == G[0] and j == G[1]:
            return ct
        for k in mv:
            x = i+k[0]
            y = j+k[1]
            if 0 <= x < H and 0 <= y < W:
                if S[x][y] == '.' and seen[x][y] == False:
                    stk.appendleft([x, y, ct+1])


ans = 0

for i in range(H):
    for j in range(W):
        if S[i][j] == '#':
            continue
        for k in range(H):
            for l in range(W):
                if S[k][l] == '#':
                    continue
                if (i, j) == (k, l):
                    continue
                ans = max(ans, BFS([i, j], [k, l]))
                # print(ans)
print(ans)