#include <iostream>
#include <algorithm>
#include <map>
using namespace std;

int main(int argc, char const *argv[]){
    int n;
    cin >> n;

    int a[n][n-1];
    for (int i=0;i<n;i++) {
        for (int j=0;j<n-1;j++) {
            cin >> a[i][j] ;
        }
    }

    int day = 0;
    int games = 0;
    int b[n];

    for ( int i = 0;i<n;i++) {
        b[i] = 0;
    }

    while (games < n*(n-1)/2) {
        int pair = 0;
        bool match[n];
        for (int i = 0;i<n;i++) {
            match[i] = false;
        }
        for (int i = 0;i<n;i++) {
            if (match[i] == true || b[i] >= n-1){
                continue;
            }
            int tar = a[i][b[i]] -1 ;
            if (! match[tar] && a[tar][b[tar]] == i+1){
                b[i] += 1;
                b[tar] += 1;
                match[i] = true;
                match[tar] = true;
                pair += 1;
            }   
        }
        if (pair == 0) {
            day = -1;
            break;
        }
        day += 1;
        games += pair;
    }

    cout << day << endl;
	return 0;
}
