import collections
INF = 1000
drc = [(-1, 0), (1, 0), (0, 1), (0, -1)]
def calc(sr, sc):
    dist = [[-1] * W for _ in range(H)]
    dist[sr][sc] = 0
    que = collections.deque()
    que.append((sr, sc))
    while len(que):
        r, c = que.popleft()
        for dr, dc in drc:
            nr, nc = r + dr, c + dc
            if nr < 0 or H <= nr or nc < 0 or W <= nc:
                continue
            if board[nr][nc] == 1 or dist[nr][nc] >= 0:
                continue
            dist[nr][nc] = dist[r][c] + 1
            que.append((nr, nc))
    return max(max(row for row in dist))



H, W = map(int, input().split())
board = [[int(x == "#") for x in input()] for _ in range(H)]
ans = 0
for r in range(H):
    for c in range(W):
        if board[r][c] == 0:
            ans = max(ans, calc(r, c))
print(ans)
