h,w=map(int,input().split())
lists=[]
from collections import deque
d=deque()
e=deque()
field=[]
distance=0
field.append([True for i in range(w+2)])
for i in range(h):
    sub=[True]
    s=input()
    for j in range(w):
        if s[j]=="#":
            sub.append(True)
        else:
            sub.append(False)
            lists.append((i+1,j+1))
    sub.append(True)
    field.append(sub)
field.append([True for i  in range(w+2)]  )           

fieldss=field.copy()
maxi=0
for i in range(len(lists)):
        distance=0
        fields=fieldss
        sy,sx=lists[i][0],lists[i][1]
        d=deque()
        e=deque()
        d.append((sy,sx))
        fields[sy][sx]=True
        while d:
            for some in d:
                some=d.popleft()
                index1,index2=some[0],some[1]

                if fields[index1-1][index2]==False:
                    fields[index1-1][index2]=True
                    e.append((index1-1,index2))
                    
                if fields[index1+1][index2]==False:
                    fields[index1+1][index2]=True
                    e.append((index1+1,index2))
                    
                if fields[index1][index2+1]==False:
                    fields[index1][index2+1]=True
                    e.append((index1,index2+1))
                    
                if  fields[index1][index2-1]==False:
                    fields[index1][index2-1]=True
                    e.append((index1,index2-1))
        distance+=1
        d=e
        e=deque()
        maxi=max(maxi,distance)
print(maxi)       
        