H, W = map(int, input().split())
maze = [input() for i in range(H)]
start_candidate = []
'''
. , #
'''

from collections import deque

direction = [
    (-1, 0),
    (0, -1),
    (1, 0),
    (0, 1)
]


def bfs(si, sj, gi, gj):
    reached = [[-1] * W for i in range(H)]
    reached[si][sj] = 0
    que = deque([[si, sj]])
    while que:
        i, j = que.popleft()
        for vi, vj in direction:
            ti, tj = i + vi, j + vj
            if ti < 0 or tj < 0 or ti > H - 1 or tj > W - 1:
                continue
            if maze[ti][tj] == '#' or reached[ti][tj] != -1:
                continue
            reached[ti][tj] = reached[i][j] + 1
            que.append([ti, tj])
        if reached[gi][gj] != -1:
            break
    return reached[gi][gj]


for i in range(H):
    for j in range(W):
        if maze[i][j] != '#':
            start_candidate.append([i, j])

from itertools import combinations

ans = 0
for c in combinations(start_candidate, 2):
    ans = max(ans, bfs(c[0][0], c[0][1], c[1][0], c[1][1]))
print(ans)
