import math
import itertools

[H, W] = map(int, input().rstrip().split(" "))
S = []


for h in range(H):
    Ss = input().rstrip()
    S.append(Ss)

max_cost = 0


for h in range(H):
    for w in range(W):
        if S[h][w] == "#":
            continue
        que = []
        history = [ [float('inf') for w in range(W)] for h in range(H)]
        que.append([h, w, 0])
        while len(que) != 0:
            [x, y, cost] = que.pop(0)
            history[x][y] = cost
            if x + 1 < H and S[x+1][y] != "#" and history[x+1][y] > cost + 1:
                que.append([x + 1, y, cost + 1])
            if y + 1 < W and S[x][y+1] != "#" and history[x][y+1] > cost + 1:
                que.append([x, y + 1, cost + 1])
            if y -1 >= 0 and S[x][y-1] != "#" and history[x][y-1] > cost + 1:
                que.append([x, y - 1, cost + 1])
            if x - 1 >= 0 and S[x-1][y] != "#" and history[x-1][y] > cost + 1:
                que.append([x-1, y, cost + 1])
        for h in range(H):
            for w in range(W):
                if history[h][w] == float('inf'):
                    history[h][w] = 0
        current_max_cost = max(list(itertools.chain.from_iterable(history)))
        if max_cost < current_max_cost:
            max_cost = current_max_cost

print(max_cost)
