from collections import deque
H, W = map(int, input().split())
G = [list(input()) for i in range(H)]


def calc(sh, sw):
    dist = [[float('inf')] * W for i in range(H)]
    directions = [(0, 1), (1, 0), (0, -1), (-1, 0)]
    dist[sh][sw] = 0
    que = deque([[sh, sw]])

    while que:
        sh, sw = que.pop()
        for dh, dw in directions:
            if not ((0 <= sh + dh < H) and (0 <= sw + dw < W)):
                continue

            if G[sh + dh][sw + dw] == '#':
                continue

            if dist[sh + dh][sw + dw] != float('inf'):
                continue

            dist[sh + dh][sw + dw] = dist[sh][sw] + 1
            que.appendleft([sh + dh, sw + dw])

    ret = 0
    for d in dist:
        for w in range(W):
            if d[w] == float('inf'):
                continue
            ret = max(ret, d[w])

    return ret


ans = 0
for sh in range(H):
    for sw in range(W):
        ans = max(ans, calc(sh, sw))

print(ans)
