program main
    implicit none
    integer:: N,i, no, day
    logical:: battle
    integer, allocatable:: A(:,:), noind(:)
    logical, allocatable:: isbattled(:)

    read*, N
    allocate(A(N,N-1), noind(N), isbattled(N))

    do i=1,N
        read*, A(i,1:N-1)
    enddo
    noind(1:N) = 1 
    day = 1
    battle = .true.
    do while(.true.)
        
        ! print*, '--- ---day', day
        battle = .false.
        isbattled(1:N) = .false.
        do i = 1, N
            if(isbattled(i) .eqv. .true.) cycle
            no = A(i, noind(i))
            if(isbattled(no) .eqv. .true.) cycle

            if(A(no, noind(no)) == i)then
                ! print*, i , 'vs' ,no
                noind(i) = noind(i) + 1
                noind(no) = noind(no) + 1
                isbattled(i) = .true.
                isbattled(no) = .true.
                battle = .true.
            endif
        enddo

        if (.not. battle) then
            day = day - 1
            exit
        end if

        day = day + 1
    enddo

    ! print*, noind
    do i = 1, N
        if(noind(i) /= N)then
            print'(i0)', -1
            stop
        endif
    enddo


    print'(i0)',day
end program