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

def num_to_coo(p):
    h, w = divmod(p, W)
    h += 1
    w += 1
    return h, 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
        h, w = num_to_coo(p)
        if (field[h - 1][w] == '.') and noreach[p - W]:
            q.append((p - W, c + 1))
        if (field[h + 1][w] == '.') and noreach[p + W]:
            q.append((p + W, c + 1))
        if (field[h][w - 1] == '.') and noreach[p - 1]:
            q.append((p - 1, c + 1))
        if (field[h][w + 1] == '.') and noreach[p + 1]:
            q.append((p + 1, c + 1))
    return c

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