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

Q=deque()
D=[[-1 for __ in range(W) ] for _ in range(H)]
dl=[]
def bfs():
    global M,D,Q
    d_max=1
    while Q:
        i,j,d=Q.popleft()
        nc=0
        for ni,nj in ((i+1,j),(i-1,j),(i,j+1),(i,j-1)):
            if ni<0 or nj<0 or ni>=H or nj>=W:
                continue
            if M[ni][nj]=='.' and D[ni][nj]<0:
                D[ni][nj]=d+1
                d_max=max(dmax,d+1)
                M[ni][nj]='x'
                Q.append((ni,nj,d+1))
    return d_max

ans=0
for i in range(H):
    for j in range(W):
        if M[i][j]=='.':
            dmax=0
            D[i][j]=0
            M[i][j]='x'
            for ni,nj in ((i+1,j),(i-1,j),(i,j+1),(i,j-1)):
                if ni<0 or nj<0 or ni>=H or nj>=W:
                    continue
                if M[ni][nj]=='.' and D[ni][nj]<0:
                    D[ni][nj]=1
                    M[ni][nj]='x'
                    Q.append((ni,nj,1))
                    dmax+=bfs()
            ans=max(dmax,ans)

print(ans)
