from collections import deque
h,w=map(int,input().split())
l=list()
l.append('#'*(w+2))#壁
for i in range(h):
    l.append('#'+input()+'#')
l.append('#'*(w+2))#壁
p=0
for i in range(1,h+1):
    for j in range(1,w+1):
        if l[i][j]=='#':
            continue
        s=[[-1 for a in b] for b in l]
        q=deque([[i,j]])
        s[i][j]=0
        while len(q)>0:
            a,b=q.popleft()
            for i,j in [[1,0],[0,1],[-1,0],[0,-1]]:
                if l[a+i][b+j]=='#' or s[a+i][b+j]>-1:
                    continue
                q.append([a+i,b+j])
                s[a+i][b+j]=s[a][b]+1
        p=max(s[a][b],p)
print(p)