H,W=map(int,input().split())
S=[list(input()) for i in range(H)]
inf=float("inf")
d=[[1,0],[0,1],[-1,0],[0,-1]]
ans=0
for sx in range(H):
    for sy in range(W):
        for gx in range(H):
            for gy in range(W):
                if S[sx][sy]==S[gx][gy]==".":
                    data=[[inf]*W for i in range(H)]
                    que=[[sx,sy]]
                    data[sx][sy]=0
                    count=1
                    while que:
                        h=[]
                        for x,y in que:
                            for dx,dy in d:
                                nx,ny=x+dx,y+dy
                                if 0<=nx<H and 0<=ny<W and S[nx][ny]=="." and data[nx][ny]==inf:
                                    h.append([nx,ny])
                                    data[nx][ny]=count
                        que=h
                        count+=1
                    ans=max(ans,data[gx][gy])
print(ans)