import sys
sys.setrecursionlimit(1000000)
from queue import Queue
h,w=map(int,input().split())
S=[input() for _ in range(h)]

def bfs(q):
  x,y,cnt=q.get()
  if x<0 or x>=w or y<0 or y>=h:
    return
  elif S[y][x]=='#':
    return
  elif memo[y][x]<0:
    memo[y][x]=cnt
    q.put([x-1,y,cnt+1])
    q.put([x+1,y,cnt+1])
    q.put([x,y-1,cnt+1])
    q.put([x,y+1,cnt+1])

ans=0
memo=[[-1]*w for _ in range(h)]
for x in range(w):
  for y in range(h):
    if x==h//2+1 and y==w//2+1:
      break
    if memo[y][x]==1: continue
    q=Queue()
    q.put([x,y,0])
    memo=[[-1]*w for _ in range(h)]
    while not q.empty():
      bfs(q)
    ans=max(ans,max(max(memo)))
print(ans)