from queue import Queue
H, W = map(int, input().split())
S = [list(input()) for _ in range(H)]

q = Queue()
searched = [[False for _ in range(W)] for __ in range(H)]
dist = [[-1 for _ in range(W)] for __ in range(H)]

def bfs(x, y, d):
    if not (0 <= x < W and 0 <= y < H):
        return
    if S[y][x] == '#':
        return
    if searched[y][x]:
        return
    searched[y][x] = True
    dist[y][x] = d
    q.put([x, y, d])
    return

ans = 0
for s_y in range(H):
    for s_x in range(W):
        q = Queue()
        searched = [[False for _ in range(W)] for __ in range(H)]
        dist = [[-1 for _ in range(W)] for __ in range(H)]
        
        dist[s_y][s_x] = 0
        searched[s_y][s_x] = True
        
        q.put([s_x, s_y, 0])
        
        while not q.empty():
            x, y, d = q.get()
            bfs(x-1, y, d+1)
            bfs(x+1, y, d+1)
            bfs(x, y-1, d+1)
            bfs(x, y+1, d+1)
        
        dist_max = max(list(map(lambda x: max(x), dist)))
        ans = max(ans, dist_max)

print(ans)
        
