from collections import deque
import copy

def BFS(sy,sx,xy_list):
 dist=[[-1]*w for i in range(h)]
 dist[sy][sx]=0
 xy_list[sy][sx]='#'

 dq=deque()
 dq.append((sy,sx))

 while dq:
  y,x=dq.popleft()
  for dy,dx in [[1,0],[-1,0],[0,1],[0,-1]]:
   ny=y+dy
   nx=x+dx
   if 0<=ny<h and 0<=nx<w and xy_list[ny][nx]!='#':
    dq.append((ny,nx))
    xy_list[ny][nx]='#'
    dist[ny][nx]=dist[y][x]+1

 return dist

h,w=map(int,input().split())
s=[list(input()) for i in range(h)]

ans=0
for hh in range(h):
 for ww in range(w):
  if s[hh][ww]=='#':
   continue
  xy_list=copy.deepcopy(s)
  dist=BFS(hh,ww,xy_list)
  for d in dist:
   ans=max(ans,max(d))

print(ans)