from collections import deque
import numpy as np

H, W = map(int, input().split())
H += 2; W += 2
grid = []
grid.append("#" * W)
for h in range(H-2):
  grid.append("#" + input() + "#")
grid.append("#" * W)

INF = 10**9
ans = 0
for h in range(1, H-1):
  for w in range(1, W-1):
    
    if grid[h][w]=="#": continue

    dist = np.array([[INF]*W for i in range(H)])
    dist[h][w] = 0 
    q = deque([(h,w)])

    while(q):
      v_h, v_w = q.popleft()
      d_v = dist[v_h][v_w]
      for n_h, n_w in ((v_h, v_w-1),(v_h, v_w+1),(v_h-1, v_w),(v_h+1, v_w)):
        if grid[n_h][n_w]=="#": continue
        d_v = dist[v_h][v_w]
        d_n = d_v + 1
        if (dist[n_h][n_w] == -1) & (d_n > dist[n_h][n_w]):
          continue
        
        dist[n_h][n_w] = d_n
        q.append((n_h,n_w))


    
      dist_m = max(x for x in dist.flatten() if x < INF)
      ans = max(ans, dist_m)

print(ans)

      


    