from collections import deque

H,W  = [int(v) for v in input().split()]
S = ['#'+input()+'#' for _ in range(H)]
S.insert(0,"#"*(W+2))
S.append("#"*(W+2))

ans = 0

for y in range(1,H+1):
    for x in range(1,W+1):
        if S[y][x] == "#": continue
        queue = deque([[x,y,0]])
        visited = [[False] * (W+2) for _ in range(H+2)]
        visited[y][x] = True

        while queue:
            x,y,c = queue.pop()
            for ny,nx in [[y+1,x],[y,x+1],[y-1,x],[y,x-1]]:
                if visited[ny][nx] or S[ny][nx] == '#': continue
                visited[ny][nx] = True
                queue.appendleft([nx,ny,c+1])
            ans = max(ans,c)
print(ans)
