import sys
import itertools

sys.setrecursionlimit(10**7)

H, W = map(int, input().split())

S = []
for _ in range(H):
    S.extend(list(input()))

dxs = [-1, 1, -W, W]

sx, sy = 0, 0


def f(sx, sy):
    dist = [-1] * (H * W)
    s = sx * W + sy
    # print('s', s)
    if S[s] == '#':
        return -1
    q = [s]
    dist[s] = 0
    while q:
        qq = []
        for x, dx in itertools.product(q, dxs):
            if x % W == 0 and dx == -1:
                continue
            if x % W == W - 1 and dx == 1:
                continue
            y = x + dx
            # print('y', y)
            if y >= len(S) or y < 0:
                continue
            if S[y] == '#':
                continue
            if dist[y] != -1:
                continue
            dist[y] = dist[x] + 1
            qq.append(y)
        # print('qq', qq)
        q = qq
    # return dist, max(dist)
    return max(dist)


ans = 0
for r in range(H):
    for c in range(W):
        # _, v = f(r, c)
        v = f(r, c)
        # print('rcv', r, c, v)
        if ans < v:
            ans = v
print(ans)
