#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = 1e3+5;

int n;
int a[N][N],t[N],p[N];	//a siai zyunban,  t  siai counter, p 
queue<int>q[2];

int main(){
	scanf("%d",&n);
	for(int i=1;i<=n;++i)
	for(int j=1;j<n;++j)
	scanf("%d",&a[i][j]);
	for(int i=1;i<=n;++i)q[0].push(i);
	int now=1,nex=0;
	for(int day=1,tot=n*(n-1)/2;day<=n*(n-1)/2;++day){
		swap(now,nex);
		while(!q[now].empty()){
			int x=q[now].front();q[now].pop();
			int y=a[x][++t[x]];  //player NO.[x] no [++t[x]]banme no taisen
			if(p[y]==x){		//player y mo next vs y ? or not
				tot--;				// siai syouka
				q[nex].push(x);		//today ha mou siai sinai  //nex(tomorrow)
				q[nex].push(y);
				p[x]=p[y]=0;
			}
			else p[x]=y;		//player x   next_vs y
		}
		if(!tot){
			cout<<day<<endl;
			return 0;
		}
	}
	cout<<-1<<endl;
	return 0;
} 