program kadai
    implicit none
integer  ::  n
integer,allocatable  ::  a(:,:)
integer,allocatable  ::  now(:)
integer,allocatable  ::  rest(:)
integer  ::  i,j,move,day,num,for

read(*,*) n
allocate(a(n,n-1))
allocate(now(n))
allocate(rest(n))

do i=1,n
    read(*,*) a(i,:)
end do

now=1
rest=0
move=0
num=0
day=1

do j=1,n*n
    do i=1,n
        for=a(i,now(i))
        if (a(for,now(for))==i .and. rest(for)==0 .and. rest(i)==0) then
            !write(*,*) i,"vs",for
            now(i)=now(i)+1
            now(for)=now(for)+1
            if (now(i)>n .or. now(for)>n) then
                write(*,*) -1
                !write(*,*) now,num
                stop
            end if
            move=1
            num=num+1
            rest(i)=1
            rest(for)=1
        end if
        if (num==n*(n-1)/2) then
            write(*,*) day
            stop
        end if
    end do
    if (move==0) then
        write(*,*) -1
        stop
    end if
    day=day+1
    rest=0
end do

write(*,*) -1


stop
contains

end program kadai