import queue
h,w=map(int,input().split())
s=[list(input()) for i in range(h)]

inf=100000000
ma=[]
for i in range(h):
    for j in range(w):
        x=[[inf for i_sub in range(w)] for j_sub in range(h)]
        q=queue.Queue()
        d=-1
        q.put([i,j])
        while q.qsize()!=0:
            d+=1
            l=q.qsize()
            for t in range(l):
                I,J=q.get()
                x[I][J]=d
                if I-1>=0 and s[I-1][J]=="." and x[I-1][J]==inf:
                    q.put([I-1,J])
                if I+1<=h-1 and s[I+1][J]=="." and x[I+1][J]==inf:
                    q.put([I+1,J])
                if J-1>=0 and s[I][J-1]=="." and x[I][J-1]==inf:
                    q.put([I,J-1])
                if J+1<=w-1 and s[I][J+1]=="." and x[I][J+1]==inf:
                    q.put([I,J+1])
        ma_sub=0
        for k in range(h):
            for l in range(w):
                if x[k][l]!=inf:
                    ma_sub=max(ma_sub,x[k][l])
        ma.append(ma_sub)
print(max(ma))
