H, W = map(int, input().split())
l = [input() for i in range(H)]

from collections import deque
d = [(1, 0), (-1, 0), (0, 1), (0, -1)]

ans = 0
for i in range(H):
    for j in range(W):
        if l[i][j] == '#':
            continue
        ll = [[0] * W for _ in range(H)]
        q = deque([(i, j)])
        while q:
            y, x = q.popleft()
            for dy, dx in d:
                if 0 <= y+dy < H and 0 <= x+dx < W and l[y+dy][x+dx] == '.' and ll[y+dy][x+dx] == 0:
                    n = ll[y][x] + 1
                    ll[y+dy][x+dx] = n
                    if ans < n:
                        ans = n
                    q.append((y+dy, x+dx))

print(ans)