h,w=map(int,input().split())
s=["."]*h
for i in range(h):
    s[i]=input()
ans=0    
n=[[100]*h]*w
def check(i,j):
   
    n[i][j]=0   
    if 1<=j:
        if s[i][j-1]=="." and n[i][j-1]==100:
            check2(i,j-1)
    if j<=w-2:
        if s[i][j+1]=="." and n[i][j+1]==100:
            check2(i,j+1)
    if 1<=i:
        if s[i-1][j]=="." and n[i-1][j]==100:
            check2(i-1,j)
    if i<=h-2:
        if s[i+1][j]=="." and n[i+1][j]==100:
            check2(i+1,j)
    for i in range(h):
        for j in range(w):
            if n[i][j]==100:n[i][j]=0
           
    return max(max(n))

def check2(i,j):
    if 1<=j:n[i][j]=min(n[i][j],n[i][j-1])+1
    if j<=w-2:n[i][j]=min(n[i][j],n[i][j+1])+1
    if 1<=i:n[i][j]=min(n[i][j],n[i-1][j])+1
    if i<=h-2:n[i][j]=min(n[i][j],n[i+1][j])+1 
    if 1<=j:
        if s[i][j-1]=="." and n[i][j-1]==100:
            check2(i,j-1)
    if j<=w-2:
        if s[i][j+1]=="." and n[i][j+1]==100:
            check2(i,j+1)
    if 1<=i:
        if s[i-1][j]=="." and n[i-1][j]==100:
            check2(i-1,j)
    if i<=h-2:
        if s[i+1][j]=="." and n[i+1][j]==100:
            check2(i+1,j)
    
for i in range(h):
    for j in range(w):
        if s[i][j]==".":
            a=check(i,j)
            ans=max(ans,a)
print(ans-1)