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

def bfs(start):
    dist = [0] * (H * W)
    q = deque([start])
    while q:
        p = q.popleft()
        c = dist[p] + 1
        print(p)
        if p % W == 0:
            nex_li = [p-W, p+W, p+1]
        elif p % W == W - 1:
            nex_li = [p-W, p+W, p-1]
        else:
            nex_li = [p-W, p+W, p-1, p+1]
        for nex in nex_li:
            if nex != start and nex >= 0 and nex < H * W and field[nex] == '.':
                dist[nex] = c
                q.append(nex)
    return dist[p]

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