def bfs(H, W, h, w, maze):
    if maze[h][w] == '#':
        return 0
    visited = []
    distance = []
    for i in range(H):
        visited.append([False] * W)
        distance.append([0] * W)
    position = [[h, w]]
    current = 0
    while len(position) > 0:
        h, w = iter(position.pop(0))
        current = distance[h][w]
        if h - 1 >= 0 and maze[h-1][w] == '.' and not(visited[h-1][w]):
            distance[h-1][w] = current + 1
            visited[h-1][w] = True
            position.append([h-1, w])
        if h + 1 < H and maze[h+1][w] == '.' and not(visited[h+1][w]):
            distance[h+1][w] = current + 1
            visited[h+1][w] = True
            position.append([h+1, w])
        if w - 1 >= 0 and maze[h][w-1] == '.' and not(visited[h][w-1]):
            distance[h][w-1] = current + 1
            visited[h][w-1] = True
            position.append([h, w-1])
        if w + 1 < W and maze[h][w+1] == '.' and not(visited[h][w+1]):
            distance[h][w+1] = current + 1
            visited[h][w+1] = True
            position.append([h, w+1])
    return current


H, W = map(int, input().split())
maze = []
for i in range(H):
    maze.append(input())
M = 0
for h in range(H):
    for w in range(W):
        d = bfs(H, W, h, w, maze)
        if d > M:
            M = d
print(M)
