from collections import deque, defaultdict


def bfs():
    adjacent = [(1, 0), (0, 1), (-1, 0), (0, -1)]  # 遷移先を網羅する
    cnt = defaultdict(int)
    hoge = 0
    while len(q):
        cx, cy = q.popleft()  # 現在の位置
        for a, b in adjacent:
            if 0 > cx+a or 0 > cy+b:
                continue
            if abs(cx+a) >= H or abs(cy+b) >= W:
                continue
            if visited[cx+a][cy+b]:
                continue
            if gridgraph[cx+a][cy+b] == "#":
                continue
            cnt[(cx+a, cy+b)] = cnt[(cx, cy)] + 1
            hoge = max(hoge, cnt[(cx+a, cy+b)])
            q.append((cx+a, cy+b))
            visited[cx+a][cy+b] = True
    return hoge


H, W = map(int, input().split())
gridgraph = [input() for _ in range(H)]
# print(gridgraph)

ans = 0
for i in range(H):
    for j in range(W):
        visited = [[False]*W for _ in range(H)]
        tmp = 0
        # 開始位置がi, j
        q = deque()
        q.append((i, j))
        visited[i][j] = True
        ans = max(ans, bfs())

print(ans)
