def astar(start, goal, S, H, W):
  if S[start[0]][start[1]] == '#' or S[goal[0]][goal[1]] == '#':
    return -1
  else:
    INF = 10**9
    D = [[INF]*W for h in range(H)]
    D[start[0]][start[1]] = 0
    next_node = [start]
    while next_node:
      now_y, now_x = next_node.pop()
      d = D[now_y][now_x]
      for x, y in [[-1, 0], [1, 0], [0, -1], [0, 1]]:
        if now_y+y<0 or now_y+y>=H or now_x+x<0 or now_x+x>=W:
          continue
        if S[now_y+y][now_x+x] == '.':
          if D[now_y+y][now_x+x] > d + 1:
            D[now_y+y][now_x+x] = D[now_y][now_x] + 1
            next_node.append([now_y+y, now_x+x])
    
    if D[goal[0]][goal[1]] < INF:
      return D[goal[0]][goal[1]]
    else:
      return -1


H, W = map(int, input().split())
nodes = []
for h in range(H):
  for w in range(W):
    nodes.append([h, w])

S = []
for h in range(H):
  S.append(list(input()))

ans = 0
for start in nodes:
  for goal in nodes:
    ans = max(ans, astar(start, goal, S, H, W))

print(ans)