H,W=map(int,input().split())
grid=[None]*H
for i in range(H):
  grid[i]=input()

ans=0
from collections import deque
for i in range(H):
  for j in range(W):
    q=deque()
    q.append([i,j,0])
    seen=[[False for j in range(W)] for i in range(H)]
    while q:
      node=q.popleft()
      y=node[0]
      x=node[1]
      dist=node[2]
      if grid[y][x]=="#":
        continue
      if seen[y][x]:
        continue
      seen[y][x]=True
      if dist>ans:
        ans=dist
      cases=((0,1),(0,-1),(1,0),(-1,0))
      for c in cases:
        if 0<=y+c[0]<H and 0<=x+c[1]<W:
          q.append([y+c[0],x+c[1],dist+1])
      
print(ans)    