n,m=map(int,input().split())
l=["#"+input()+"#" for an  in range(n)]
l=["#"*(m+2)]+l+["#"*(m+2)]
inf=10**7
from queue import Queue as qu
mo=[(1,0),(-1,0),(0,1),(0,-1)]
ret=0
for i in range(1,n+1):
  for j in range(1,m+1):
    if l[i][j]==".":
      q=qu()
      step=[[inf for c in range(m+2)] for x in range(n+2)]
      step[i][j]=0
      q.put((i,j))
      while not q.empty():
        d=q.get()
        for g in mo:
          c,cc=g[0]+d[0],g[1]+d[1]
          if step[c][cc]==inf and l[c][cc]==".":
            q.put((c,cc))
            step[c][cc]=step[d[0]][d[1]]+1
            ret=max(ret,step[c][cc])
print(ret)