import java.io._
import java.util.StringTokenizer
import scala.util.control.Breaks.{breakable,break}
import scala.collection.mutable.{Map, Queue, PriorityQueue}

object Main extends App {
  val in = new InputReader(System.in)
  val pw = new PrintWriter(System.out)

  val N = in.next().toInt
  val A = Array.ofDim[Int](N+1, N)
  for (y <- 1 to N; x <- 1 to N-1) {
    A(y)(x) = in.next().toInt
  }



  //
  def getInd(p: (Int, Int)): Int = {
    val (x, y) = p
    (x-1) * N + (y-1)
  }

  val depend = Array.fill[Set[(Int, Int)]](N*N)(Set())
  val degree = new Array[Int](N*N)

  
  for (a <- 1 to N; b <- a+1 to N) {
    degree(getInd(a->b)) = 0
  }

  // fill depend and degree
  var pre = (0, 0)
  for (a <- 1 to N; b <- 1 to N-1) {
    val s = a min A(a)(b)
    val t = a max A(a)(b)
    if(b == 1) {
      pre = (s, t)
    }
    else {
      if (!depend(getInd(pre))(s->t)) {
        depend(getInd(pre)) += (s -> t)
        degree(getInd(s->t)) += 1
      }

      pre = (s, t)
    }
  }

  throw new RuntimeException("hogeee")

  var sum = N * (N-1) / 2
  var stack = List[(Int, Int)]()
  for (a <- 1 to N; b <- a+1 to N) {
    val value = degree(getInd(a->b))
    if (value == 0) {
      stack = (a->b) :: stack
    }
  }


  var ans = 0
  while(!stack.isEmpty) {
    ans += 1
    var nexts = List[(Int, Int)]()
    for (key <- stack) {
      sum -= 1
      for (v <- depend(getInd(key))) {
        degree(getInd(v)) -= 1
        if (degree(getInd(v)) == 0)
          nexts = v :: nexts
      }
    }
    stack = nexts
  }

  if (sum > 0)
    ans = -1

  println(ans)


}


class InputReader(stream: InputStream) {
  private val reader = new BufferedReader(new InputStreamReader(stream))
  private var tokenizer: StringTokenizer = new StringTokenizer(reader.readLine())
  def next(): String = {
    while (!tokenizer.hasMoreTokens()) {
      tokenizer = new StringTokenizer(reader.readLine())
    }
    tokenizer.nextToken()
  }
}
