H,W=map(int, input().split())
S = [input() for i in range(H)]
m=H*W
l=[[None]*m for i in range(m)]
L=[0]*m
for i in range(H):
    for j in range(W):
        if S[i][j]==".":
            L[i*W+j]=1
for i in range(m):
    for j in range(m):
        if L[i] and L[j]:
            if i==j:
                l[i][j]=0
            elif abs(i-j)==W:
                l[i][j]=1
            elif abs(i-j)==1 and (i+j)%W!=W-1:
                l[i][j]=1
            else:
                l[i][j]=400
for i in range(m):
    if L[i]:
        for j in range(m):
            if L[j]:
                for k in range(m):
                    if L[k]:
                        if l[i][j]+l[i][k]<l[j][k]:
                            l[j][k]=l[i][j]+l[i][k]
M=0
for i in l:
    for j in i:
        if j:
            if M<j:
                M=j
print(M)