def solve(maze,H, W, S, G):
    next_set = set()
    next_set.add(S)
    seen = [[False]*W for _ in range(H)]
    n = 0
    while True:
        curr_set = list(next_set)
        next_set = set()
        for x in curr_set:
            seen[x[0]][x[1]] == True
            if x == G:
                return n
            move_to = [(x[0]+1, x[1]), (x[0], x[1]+1), (x[0]-1, x[1]), (x[0], x[1]-1)] 
            for m in move_to:
                h, w = m
                if 0 <= h < H and 0<= w < W:
                    if maze[h][w] and seen[h][w] == False:
                        next_set.add(m)
        n += 1
    
    return print('error')

H, W = list(map(int, input().split()))
maze = [[True]*W for _ in range(H)]
for h in range(H):
    row = input()
    for w in range(W):
        if row[w] == '#':
            maze[h][w] = False

ans = 0
for i in range(H*W-1):
    for j in range(i+1, H*W):
        S = (i//W, i%W)
        G = (j//W, j%W)
        if maze[S[0]][S[1]] and maze[G[0]][G[1]]:
            ans = max(ans, solve(maze, H, W, S, G))

print(ans)