H, W = list(map(int, input().split(" ")))
S = []
for h in range(H) :
  S.append(list(input()))
  
l_path = [[W*H for i in range(W*H)] for j in range(W*H)]

for h in range(H) :
  for w in range(W) :
    if((w+1<W) and (S[h][w] == ".") and (S[h][w+1] == ".")) :
      l_path[W*h+w][W*h+(w+1)] = 1
      l_path[W*h+(w+1)][W*h+w] = 1
    if((h+1<H) and (S[h][w] == ".") and (S[h+1][w] == ".")) :
      l_path[W*h+w][W*(h+1)+w] = 1
      l_path[W*(h+1)+w][W*h+w] = 1
       
for k in range(W*H) :
  for i in range(W*H) :
    for j in range(W*H) :
      if(l_path[i][j] > l_path[i][k] + l_path[k][j]) :
        l_path[i][j] = l_path[i][k] + l_path[k][j]

max_path = 0
for i in range(W*H) :
  for j in range(W*H) :
    if((l_path[i][j] < W*H) and (max_path < l_path[i][j])) :
      max_path = l_path[i][j]
        
print(max_path)

