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):
    cost = [-1] * (H * W)
    q = deque()
    q.append((s, 0))
    while q:
        p, c = q.popleft()
        cost[p] = c
        h, w = num_to_coo(p)
        if (field[h - 1][w] == '.') and p - W >= 0 and (cost[p - W] == -1):
            q.append((p - W, c + 1))
        if (field[h + 1][w] == '.') and p + W < H * W and (cost[p + W] == -1):
            q.append((p + W, c + 1))
        if (field[h][w - 1] == '.') and p - 1 >= 0 and (cost[p - 1] == -1):
            q.append((p - 1, c + 1))
        if (field[h][w + 1] == '.') and p + 1 < H * W and (cost[p + 1] == -1):
            q.append((p + 1, c + 1))
    return c

ans = -1
for s in range(H * W):
    ans = max(ans, bfs(s))
print(ans)
