h,w=map(int,input().split())
a=['*'*(w+2)]+['*'+input()+'*' for _ in range(h)]+['*'*(w+2)]
from collections import deque
ans=0
for p in range(h):
  for q in range(w):
    d=deque()
    m=0
    if a[p+1][q+1]=='.':
      d.append([p+1,q+1])
      c=[[10000]*w for _ in range(h)]
      c[p][q]=1
      di=[[0,1],[1,0],[-1,0],[0,-1]]
      while d:
        g=d.popleft()
        for i in di:
          x=g[0]+i[0]
          y=g[1]+i[1]
          if a[x][y]=='.':
            if c[x-1][y-1]==10000:
              d.append([x,y])
              c[x-1][y-1]=c[g[0]-1][g[1]-1]+1
      for i in range(h):
        for j in range(w):
          if c[i][j]!=10000:
            m=max(m,c[i][j])
    ans=max(ans,m)
print(ans-1)