from collections import deque
H, W = map(int, input().split())
field = ''
for i in range(H):
    field += input()
field += '#' * W

def bfs(s):
    noreach = [1] * (H * W)
    for _ in range(W):
        noreach.append(0)
    q = deque()
    q.append((s, 0))
    while q:
        p, c = q.popleft()
        noreach[p] = 0
        if (field[p - W] == '.') and noreach[p - W]:
            q.append((p - W, c + 1))
        if (field[p + W] == '.') and noreach[p + W]:
            q.append((p + W, c + 1))
        if (field[p - 1] == '.') and noreach[p - 1] and p % W != 0:
            q.append((p - 1, c + 1))
        if (field[p + 1] == '.') and noreach[p + 1] and p % W != W - 1:
            q.append((p + 1, c + 1))
    return c

ans = -1
for s in range(H * W):
    if field[s] == '.':
        ans = max(ans, bfs(s))
print(ans)
