from collections import deque
H, W = [int(_) for _ in input().split()]
e = "#" * (W + 2)
maze = [e]
for i in range(H):
    s = input()
    maze.append("#" + s + "#")
maze.append(e)
max_count = 0
for h in range(H):
    for w in range(W):
        visited = [[False for i in range(W+2)] for j in range(H+2)]
        if maze[h+1][w+1] == '#':
            continue
        q = deque([[w+1, h+1, 0]])
        def search(x, y, c):
            if maze[y][x] == '.' and not visited[y][x]:
                q.append([x, y, c+1])
                visited[y][x] = True
        count = 0
        while len(q) != 0:
            p = q.popleft()
            search(p[0]+1, p[1], p[2])
            search(p[0]-1, p[1], p[2])
            search(p[0], p[1]+1, p[2])
            search(p[0], p[1]-1, p[2])
            count = p[2]
        max_count = max(max_count, count)
print(max_count)




