h, w = map(int, input().split())
MAZE = ['#'*(w+2)]
for _ in range(h):
    MAZE.append("#"+input()+"#")
else:
    MAZE.append('#'*(w+2))
INF = 10**3
dp = [[INF]*(w+2) for _ in range(h+2)]
directions = [(-1, 0), (0, 1), (1, 0), (0, -1)]

def bfs(pos):
    x, y = pos
    can_go = []
    for i, j in directions:
        if MAZE[x+i][y+j] == '.':
            if dp[x+i][y+j] != INF:
                continue
            dp[x+i][y+j] = min(dp[x+i+v][y+j+w]+1 for v, w in directions)
            can_go.append((x+i, y+j))
    for x, y in can_go:
        bfs((x, y))

ans = 0
for i in range(1, h+1):
    for j in range(1, w+1):
        if MAZE[i][j] == '#':
            continue
        start_idx = (i, j)
        dp = [[INF]*(w+2) for _ in range(h+2)]
        dp[i][j] = 0
        bfs(start_idx)
        ans = max(ans, max(max([x for x in row if x < INF]+[0]) for row in dp))

print(ans)
