import queue
H,W = map(int,input().split())

Map = []
Map.append(list('@'*(W+2)))
for i in range(H):
  s = list('@'+input()+'@')
  Map.append(s)
Map.append(list('@'*(W+2)))
  
#400*400 = 160000 = 1.6*10**5
#スタートとゴール用
select = []
for i in range(H+2):
 if((i != 0)and(i != H+1)):
  for j in range(W+2):
   if((j != 0)and(j != W+1)):
    for k in range(H+2):
     if((k != 0)and(k != H+1)):
      for l in range(W+2):
       if((l != 0)and(l != W+1)):
         select.append([i,j,k,l])
#print(len(select))          

#幅優先探索
def bfs(sy,sx,gy,gx,Map):
  qy,qx = queue.Queue(),queue.Queue()
  qy.put(sy),qx.put(sx)
  ans = 0
  while(1):
    if(qx.empty() == True): return ans
    #座標の取り出し
    y,x = qy.get(),qx.get()
    if((y == gy)and(x == gx)): #ゴールなら終了
      ans = Map[y][x]
      #for i in range(H+2):
      #   print(Map[i])
      #print('______________')
      return ans
    
    #次に進むところ
    vec_y = [0,0,1,-1]
    vec_x = [1,-1,0,0]
    for i in range(4):
      if(Map[y+vec_y[i]][x+vec_x[i]] == '.'):
        Map[y+vec_y[i]][x+vec_x[i]] = Map[y][x] + 1
        qy.put(y+vec_y[i]),qx.put(x+vec_x[i])
           
ans = 0 
for s in range(len(select)):
  sy,sx = select[s][0], select[s][1] 
  gy,gx = select[s][2], select[s][3]
  
  Map2 = []
  for i in range(H+2):
    Map2.append(Map[i])
    
  #スタートとゴールの設置
  if((Map2[sy][sx] == '.')and(Map2[gy][gx] == '.')):
   Map2[sy][sx] = 0
   #幅優先探索
   tmp_ans = bfs(sy,sx,gy,gx,Map2)
   #print(sy,sx,gy,gx)
   #print(tmp_ans)
   ans = max(ans,tmp_ans)

print(ans)