h,w=map(int,input().split())
l=[list(map(str,input())) for _ in range(h)]  
def maze(MAZE,sx,sy,gx,gy):
  dmap=[[h*w]*w for _ in range(h)]
  dmap[sx][sy]=0
  dist=h*w
  cand=[]
  visited=set()
  if sx==gx and sy==gy:
    dist=0
  else:
    cand.append([sx,sy])
  while len(cand)!=0:
    x,y=cand.pop()
    visited.add((x,y))
    for next_y,next_x in [(y+1, x), (y, x+1), (y, x-1), (y-1, x)]:
      if next_x==gx and next_y==gy:
        if dist>dmap[x][y]+1:
          dist=dmap[x][y]+1
        break
      elif 0<=next_x<=h-1 and 0<=next_y<=w-1 and MAZE[next_x][next_y]=='.' and not (next_x,next_y) in visited:
        cand.append([next_x,next_y])
        dmap[next_x][next_y]=min(dmap[x][y]+1,dmap[next_x][next_y])
  return dist
c=0
for ix in range(h):
  for iy in range(w):
    if l[ix][iy]!='#':
      for jx in range(h):
        for jy in range(w):
          if l[jx][jy]!='#':
            d=maze(l,ix,iy,jx,jy)
            if c<d:
              c=d
print(c)