from collections import deque

H, W = map(int, input().split())

G = []
for i in range(H):
    G.append(list(input()))


move = [[0, 1], [0, -1], [-1, 0], [1, 0]]
saidai = 0
for sy in range(H):
    for sx in range(W):
        if G[sy][sx] == ".":
            queue = deque([[sy, sx]])
            visited = [[0]*W for i in range(H)]
            while queue:
                y, x = queue.popleft()
                for i in move:
                    iy, ix = i[0], i[1]
                    if 0<=iy+y<H and 0<=ix+x<W and G[iy+y][ix+x] =="." and visited[iy+y][ix+x] == 0:
                        visited[iy+y][ix+x] = visited[y][x] + 1
                        queue.append([iy+y, ix+x])
        
            for i in range(H):
                for j in range(W):
                        saidai = max(saidai, visited[i][j])
            queue = []
            visited = [[0]*W for i in range(H)]
print(saidai)