import queue
import copy
D = ((0, -1), (0, 1), (-1, 0), (1, 0))

def bfs(S, s):
    M = copy.deepcopy(S)
    q = queue.Queue()
    q.put((s[0], s[1], 0))
    dis = 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] != '#':
                M[y][x] = '#'
                q.put((x, y, cur[2]+1))
                dis = max(dis, cur[2] + 1)

    return dis


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

S[0] = ['#'] * (W + 2)
for h in range(1, H+1):
    S[h] = ['#'] + [c for c in 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] != '#':
            ans = max(ans, bfs(S, (sx, sy)))

print(ans)