from collections import deque

H,W=[int(i) for i in input().split()]
# c=[[i for i in input().split()] for _ in range(h)]
C=list(input() for _ in range(H))
C=list(list(i) for i in C) #visited_listを用いずに壁にしていく方法ではリスト化が必要

def bfs(maze,s1,s2,g1,g2):
    for y in range(H):
        for x in range(W):
            if maze[y][x]!='#':
                maze[y][x]=10**9

    maze[s1][s2]=0
    que=deque([[s1,s2]])
    while que:
        y,x=que.popleft()
        for i,j in [(1,0),(0,1),(-1,0),(0,-1)]:
            nexty,nextx=y+i,x+j
            if nexty >= 0 and nexty < H and nextx >= 0 and nextx < W:
                dist=maze[nexty][nextx]
                if dist!='#':
                    if dist>maze[y][x]+1:
                        maze[nexty][nextx]=maze[y][x]+1
                        que.append([nexty,nextx])
    return maze[g1][g2]

ans=0
for s1,c_w in enumerate(C):
    for s2,c in enumerate(c_w):
        if C[s1][s2]=="#":
            break
        else:
            for g1,c_w in enumerate(C):
                for g2,c in enumerate(c_w):
                    if C[g1][g2]=="#":
                        break
                    else:
                        temp=bfs(C,s1,s2,g1,g2)
                        ans=max(temp,ans)
print(ans)
