program league
  implicit none
  integer :: n, a(1000,1000) = 0, i, j, l, k(1000) = 1, m = 0
  logical :: used(1000) = .false., change
  read(*,*) n
  do i = 1, n
    read(*,*) a(i,1:n-1)
  end do
  do while (any(k(1:n) < n))
    m = m+1
    used(1:n) = k(1:n) == n
    change = .false.
    do i = 1, n
      if (used(i)) cycle
      j = a(i,k(i))
      if (used(j)) cycle
      if (a(j,k(j)) == i) then
        k(i) = k(i)+1
        k(j) = k(j)+1
        used(i) = .true.
        used(j) = .true.
        change = .true.
      end if
    end do
    if (.not.change) then
      m = -1
      exit
    end if
  end do
  write(*,'(i0)') m
end program league