from  collections import deque
H,W=list(map(int,input().split()))
S=[list(input()) for i in range(H)]
dxdy=[[1,0],[-1,0],[0,1],[0,-1]]
ans=0
for w in range(W):
    for h in range(H):
        temp=0
        stack=deque([[h,w]])
        visited=[[-1 for i in range(W)]for j in range(H)]
        visited[h][w]=0
        while stack:
            x,y=stack.popleft()
            for i in dxdy:
                nx,ny=x+i[0],y+i[1]
                if 0<=nx<H and 0<=ny<W and S[nx][ny]!='#'and visited[nx][ny]==-1:
                    stack.append([nx,ny])
                    visited[nx][ny]=visited[x][y]+1
        temp=max([j for i in visited for j in i])
        ans=max(ans,temp)
print(ans)