output_description: If it is possible to schedule all the matches so that all of the conditions
  are satisfied, print the minimum number of days required; if it is impossible,
  print `-1`.
  
  * * *
input_description: Input is given from Standard Input in the following format:
  
      
      
      N
      A_{1, 1} A_{1, 2} \ldots A_{1, N-1}
      A_{2, 1} A_{2, 2} \ldots A_{2, N-1}
      :
      A_{N, 1} A_{N, 2} \ldots A_{N, N-1}
attempt: N = int(input())
  
  X = N + 1
  
  
  def to_node(i, j):
      if i < j:
          return i * X + j
      else:
          return j * X + i
  
  
  def parse_node(node):
      return (node // X, node % X)
  
  
  a_table = []
  v_table = []
  r_table = []
  for i in range(N):
      for j in range(N):
          v_table.append(set())
          r_table.append(set())
  
  for i in range(N):
      row = [j - 1 for j in map(int, input().strip().split())]
      a_table.append(row)
      prev = to_node(i, row[0])
      for j in range(1, N - 1):
          node = to_node(i, row[j])
          v_table[prev].add(node)
          r_table[node].add(prev)
          prev = node
  
  
  def t_sort():
      queue = set()
      for i in range(N):
          for j in range(i):
              node = to_node(i, j)
              if len(r_table[node]) == 0:
                  queue.add(node)
      queue = [(node, 1) for node in queue]
      # 	print(queue)
  
      schedule = [set() for i in range(N * N)]
      while queue:
          node, day = queue.pop()
          i, j = parse_node(node)
          # 		print(i, j)
          while True:
              s = schedule[day]
              day += 1
              if not (i in s or j in s):
                  s.add(i)
                  s.add(j)
                  for next_node in v_table[node]:
                      table = r_table[next_node]
                      table.remove(node)
                      if len(table) == 0:
                          queue.append((next_node, day))
                  break
  
      for i in range(N):
          for j in range(i):
              node = to_node(i, j)
              if len(r_table[node]) != 0:
                  return -1
  
      for i in range(N * N - 1, 0, -1):
          if len(schedule[i]) != 0:
              return i
  
      return -1
  
  
  # print(a_table)
  # for row in v_table:
  # 	print(list(map(lambda x: (x // X, x % X), row)))
  
  print(t_sort())
  
problem_description: Statement
  
  N players will participate in a tennis tournament. We will call them Player 1,
  Player 2, \ldots, Player N.
  
  The tournament is round-robin format, and there will be N(N-1)/2 matches in
  total. Is it possible to schedule these matches so that all of the following
  conditions are satisfied? If the answer is yes, also find the minimum number
  of days required.
  
    * Each player plays at most one matches in a day.
    * Each player i (1 \leq i \leq N) plays one match against Player A_{i, 1}, A_{i, 2}, \ldots, A_{i, N-1} in this order.
samples: [{"input": "3\n    2 3\n    1 3\n    1 2", "output": "3\n    \n\nAll the conditions can be satisfied if the matches are scheduled for three\ndays as follows:\n\n  * Day 1: Player 1 vs Player 2\n  * Day 2: Player 1 vs Player 3\n  * Day 3: Player 2 vs Player 3\n\nThis is the minimum number of days required.\n\n* * *"}, {"input": "4\n    2 3 4\n    1 3 4\n    4 1 2\n    3 1 2", "output": "4\n    \n\nAll the conditions can be satisfied if the matches are scheduled for four days\nas follows:\n\n  * Day 1: Player 1 vs Player 2, Player 3 vs Player 4\n  * Day 2: Player 1 vs Player 3\n  * Day 3: Player 1 vs Player 4, Player 2 vs Player 3\n  * Day 4: Player 2 vs Player 4\n\nThis is the minimum number of days required.\n\n* * *"}, {"input": "3\n    2 3\n    3 1\n    1 2", "output": "-1\n    \n\nAny scheduling of the matches violates some condition."}]