h, w = map(int,input().split())
#alist = list(map(int, input().split()))

road=[]

for i in range(h):
    row=input()
    road.append(row)

ikel=0

for i in range(h):
    for j in range(w):
        if road[i][j]=='.':
            ikel+=1

maxrecord=0

for i in range(h):
    for j in range(w):
        turn=1
        ima=1
        now=[[i, j]]
        rlist=[]
        for hh in range(h):
            rlist.append([999]*w)
        rlist[i][j]=0
        while ima<ikel:
            #while turn<10:
            koho=[]
            for nw in now:
                koho.append([nw[0]-1, nw[1]])
                koho.append([nw[0]+1, nw[1]])
                koho.append([nw[0], nw[1]-1])
                koho.append([nw[0], nw[1]+1])
            #print(rlist)
            now=[]
            for kh in koho:
                if kh[0]>=0 and kh[1]>=0 and kh[0]<h and kh[1]<w:
                    #print(kh)
                    if road[kh[0]][kh[1]]=='.':
                        #print(kh, rlist[kh[0]][kh[1]])
                        if rlist[kh[0]][kh[1]]>turn:
                            #print(kh)
                            rlist[kh[0]][kh[1]]=turn
                            now.append([kh[0], kh[1]])
                            ima+=1
                            record=turn
            turn+=1
        #print('result', rlist)
        if record>maxrecord:
            maxrecord=record

print(maxrecord)