#include<bits/stdc++.h>
using namespace std;

int main(){
    int N = 0;
    cin >> N;
    vector<vector<int>> AL(N);
    for(int i=0; i<N; i++){
        vector<int> x(N);
        for(int j=0; j<N-1; j++){
            cin >> x[j];
        }
        AL[i] = x;
    }

    int limc = (N*(N-1))/2;

    vector<int> AI(N);
    fill(AI.begin(),AI.end(),0);

    for(int i=0; i<=limc; i++){
        bool fin = true, allmiss=true;
        vector<int> today(N);
        fill(today.begin(),today.end(),0);

        for(int j=0; j<N; j++){
            if(today[j]==1){continue;}
            if(AI[j] >= N-1){
                today[j] = 1;
                allmiss = false;
                continue;
            }else{
                fin = false;
            }

            int nextA = AL[j][AI[j]];
            //console.log(`${nextA} - ${AL[nextA][0]}`);
            if(today[nextA]==0 && AL[nextA][AI[nextA]]==j){
                today[j]=1;
                today[nextA]=1;
                allmiss = false;
            }

        }

        for(int j=0; j<N; j++){
            if(today[j]==1){
                AI[j]+=1;
            }
        }

        if(fin){
            cout << i << endl;
            return;
        }

        if(allmiss){
            cout << -1 << endl;
            return;
        }
    }

    cout << -1 << endl;

    return 0;
}