output_description: Print the minimum possible value of Z, where Z is the largest ugliness of the
  N pairs.
  
  * * *
input_description: Input is given from Standard Input in the following format:
  
      
      
      N M
      a_1 a_2 \cdots a_{2N}
attempt: n = int(input())
  list = []
  a = []
  for i in range(n):
      list.append(int(input))
  
  for i in range(1, n):
      for j in range(1, i):
          if list[i] == j:
              a.insert(j, j)
  
  if a == list:
      for i in range(n):
          print(list[i])
  else:
      print(-1)
  
problem_description: Statement
  
  Let M be a positive integer.
  
  You are given 2 N integers a_1, a_2, \ldots, a_{2 N}, where 0 \leq a_i < M for
  each i.
  
  Consider dividing the 2 N integers into N pairs. Here, each integer must
  belong to exactly one pair.
  
  We define the _ugliness_ of a pair (x, y) as (x + y) \mod M. Let Z be the
  largest ugliness of the N pairs. Find the minimum possible value of Z.
samples: [{"input": "3 10\n    0 2 3 4 5 9", "output": "5\n    \n\nOne solution is to form pairs (0, 5), (2, 3) and (4, 9), with ugliness 5, 5\nand 3, respectively.\n\n* * *"}, {"input": "2 10\n    1 9 1 9", "output": "0\n    \n\nPairs (1, 9) and (1, 9) should be formed, with ugliness both 0."}]