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_ = list(next_set)
        next_set = set()
        for h, w in curr_:
            if (h, w) == G:
                return n
            if seen[h][w]:
                continue

            seen[h][w] == True
            for x in maze[h][w]:
                next_set.add(x)
        n += 1
    
    return print('error')

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


# mazeに移動可能移動可能なマスを記録
for h in range(H):
    for w in range(W):
        if maze[h][w] == False:
            continue
        for nh, nw in [(h+1, w), (h, w+1), (h-1, w), (h, w-1)]:
            if 0 <= nh < H and 0<= nw < W:
                if maze[nh][nw] != False:
                    maze[h][w].append((nh, nw))
        # print(maze)
# print(maze)
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)