import itertools
import sys
sys.setrecursionlimit(10**5)

H, W = map(int, input().split())
field = [list(input()) for _ in range(H)]

# for e in field:
#    print("".join(e))

# H 3 W 5
poss = []
for h in range(H):
    for w in range(W):
        if field[h][w] == '.':
            poss.append([h, w])


def get_dist(start, goal):
    step = 0
    pattern = [[-1, 0], [1, 0], [0, 1], [0, -1]]
    current_positions = [start]
    ifFound = False
    while not ifFound:
        next_position = []
        step += 1
        for c_p in current_positions:
            for pat in pattern:
                n_p = [c_p[0] + pat[0], c_p[1] + pat[1]]
                if n_p[0] >= 0 and n_p[0] < H and n_p[1] >= 0 and n_p[1] < W and field[n_p[0]][n_p[1]] == '.':
                    if n_p == goal:
                        ifFound = True
                    next_position.append(n_p)
        # think when its unreachable
        current_positions = next_position
    return step


result = []
for comb in list(itertools.combinations(poss, 2)):
    result.append(get_dist(comb[0], comb[1]))
    result.append(get_dist(comb[1], comb[0]))

print(max(result))
