import queue

D = ((0, 1), (1, 0), (0, -1), (-1, 0))

def bfs(M, s, g):

    if s == g:
        return 0

    q = queue.Queue()
    q.put((s[0], s[1], 0))

    while not q.empty():
        cur = q.get()

        for d in D:
            x = cur[0] + d[0]
            y = cur[1] + d[1]
            if M[y][x] != '#':
                if (x, y) == g:
                    return cur[2] + 1
                else: 
                    q.put((x, y, cur[2]+1))

    return 20*20+1

H, W = map(int, input().split())
S = [None]*(H+2)

S[0] = '#' * (W + 2)
for h in range(1, H+1):
    S[h] = '#' + input() + '#'
S[-1] = '#' * (W + 2)

ans = 0
for sy in range(1, H+1):
    for sx in range(1, W+1):
        if S[sy][sx] != '#':
            for gy in range(sy, H+1):
                for gx in range(1, W+1):
                    if S[gy][gx] != '#' and not (sy == gy and gx < sx):
                        ans = max(ans, bfs(S, (sx, sy), (gx, gy)))

print(ans)