h,w=map(int,input().split())
s=['#'*(w+2)]
s+=['#'+input()+'#' for _ in range(h)]
s.append('#'*(w+2))
h+=2
w+=2
p=[[1,0],[0,1],[-1,0],[0,-1]]
st=[]
cnt=0
for i in range(h):
    for j in range(w):
        if s[i][j]=='.':
            st.append((i,j))
            cnt+=1
ans=0
for i in range(cnt):
    n=[st[i]]
    route={n[0]:0}
    c=1
    count=1
    while c<cnt:
        n2=[]
        for i in n:
            for j in p:
                np=(i[0]+j[0],i[1]+j[1])
                if s[np[0]][np[1]]=='.' and route.get(np,-1)==-1:
                    n2.append(np)
                    route[np]=count
                    c+=1
        n=n2
        count+=1
    ans=max(ans,count-1)
print(ans)