h,w=map(int,input().split())
s=[list(input())for i in range(h)]
h,w=20,20
s=[["."]*20for j in range(20)]
e=0
for i in range(h):
    for j in range(w):
        if s[i][j]==".":
            p=[i,j]
            q=[p]
            t=[[1]*w for j in range(h)]
            t[p[0]][p[1]]=0
            g=0
            while q:
                c=[]
                for i,j in q:
                    a=[1,-1,0,0]
                    b=[0,0,1,-1]
                    for d in range(4):
                        if 0<=i+a[d]<h and 0<=j+b[d]<w:
                            if s[i+a[d]][j+b[d]]==".":
                                if t[i+a[d]][j+b[d]]:
                                    t[i+a[d]][j+b[d]]=0
                                    c.append([i+a[d],j+b[d]])
                if len(c)==0:
                    break
                else:
                    g+=1
                    q=c[::]
            e=max(e,g)
print(e)