#include <bits/stdc++.h>

using namespace std;

short N;
short arr[1004][1004];
short pos[1004];
int did[1004], didN, chk[1004], cnt = 0;

int main(){
    scanf("%hd", &N);
    for(short i = 1; i <= N; ++i){
        for(short j = 1; j <= N - 1; ++j){
            scanf("%hd", arr[i] + j);
        }
        pos[i] = 1;
    }
    int ans = 0, All = N * (N - 1) / 2, nxt, f = 1;
    for(ans = 1; cnt < All; ++ans){
        ++didN, f = 1;
        for(short i = 1; i <= N; ++i) if(did[i] != didN && pos[i] < N){
            nxt = arr[i][pos[i]];
            if(arr[nxt][pos[nxt]] == i && did[nxt] != didN){
                did[i] = did[nxt] = didN;
                ++pos[i], ++pos[nxt];
                f = 0, ++cnt;
            }
        }
        if(f) break;
    }
    if(cnt == All) printf("%d\n", ans - 1);
    else puts("-1");
    return 0;
}
