h,w=map(int,input().split())
import sys
import queue
mok=queue.Queue()
s = [[str(c) for c in l.strip()] for l in sys.stdin]
dx=[1,0,-1,0]
dy=[0,1,0,-1]

maxx=0
for i in range(h):
  for j in range(w):
    d=[[-1]*w for k in range(h)]
    d[i][j]=0
    if s[i][j]=='.':
      mok.put([i,j])
      while not mok.empty():
        [nx,ny]=mok.get()
        for k in range(4):
          if 0<=nx+dx[k]<h and 0<=ny+dy[k]<w and s[nx+dx[k]][ny+dy[k]]=='.' and d[nx+dx[k]][ny+dy[k]]==-1:
            d[nx+dx[k]][ny+dy[k]]=d[nx][ny]+1
            if d[nx+dx[k]][ny+dy[k]]>maxx:
              maxx=d[nx+dx[k]][ny+dy[k]]
            mok.put([nx+dx[k],ny+dy[k]])

print(maxx)         
    