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], [0, 1], [1, 0]]
saidai = 0
for sy in range(H):
    for sx in range(W):
        if G[sy][sx] == "#":
            break
        queue = deque([[sy, sx]])
        G[sy][sx] = 0
        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] = 1
                    G[iy+y][ix+x] = G[y][x] + 1
                    queue.append([iy+y, ix+x])
 
        for i in range(H):
            for j in range(W):
                if G[i][j] == "#":
                    continue
                else:
                    saidai = max(saidai, G[i][j])

print(saidai)