import queue
import itertools
r,c=map(int,input().split())
s=[list(input()) for i in range(r)]
ans=0
for i1 in range(r):
    for i2 in range(c):
        for j1 in range(r):
            for j2 in range(c):
                a=[[s[j][i] for i in range(c)] for j in range(r)]
                sy,sx=i1,i2
                gy,gx=j1,j2
                if a[sy][sx]=="#" or a[gy][gx]=="#":
                    break
                #print(sy,sx,gy,gx)
                q = queue.Queue()
                d=[(-1,0),(1,0),(0,-1),(0,1)]
                a[sy][sx]=0
                for i in d:
                    if 0<=sy+i[0]<r and 0<=sx+i[1]<c and a[sy+i[0]][sx+i[1]]==".":
                        a[sy+i[0]][sx+i[1]]=1
                        q.put((sy+i[0],sx+i[1]))
                while not q.empty():
                    y,x=q.get()
                    for i in d:
                        if 0<=y+i[0]<r and 0<=x+i[1]<c and a[y+i[0]][x+i[1]]==".":
                            a[y+i[0]][x+i[1]]=a[y][x]+1
                            q.put((y+i[0],x+i[1]))
                ans=max(a[gy][gx],ans)
print(ans)

