def dfs(y, x, y0, x0, d=0):
    if y < 0 or y >= H or x < 0 or x >= W:
        return

    if seen[y][x]:
        return

    seen[y][x] = True

    if maze[y][x] == "#":
        return

    if d > dist[y0][x0]:
        dist[y0][x0] = d

    dfs(y, x+1, y0, x0, d+1)
    dfs(y+1, x, y0, x0, d+1)
    dfs(y, x-1, y0, x0, d+1)
    dfs(y-1, x, y0, x0, d+1)


dist = [[0] * W for _ in range(H)]

for i in range(H):
    for j in range(W):
        seen = [[False] * W for _ in range(H)]
        dfs(i, j, i, j)

ans = 0
for row in dist:
    for d in row:
        ans = max(ans, d)

print(ans)