#include <bits/stdc++.h>
#define N 1005
using namespace std;
int hav[N],n,ans=0,mat;
int a[N][N];
bool flag;
vector<int> ad,pos;
int main(){
	int i,j,x,y,c,d;
	cin>>n;
	mat=n*(n-1)/2;
	for(i=0;i<n;i++)
	{
		ad.push_back(i);
		for(j=0;j+1<n;j++)
		{
			cin>>x;
			a[i][j]=x-1;
		}
	}
	memset(hav,0,sizeof(hav));
	while(1)
	{
		ans++;
		bool book[N]={};
		flag=true;
		pos.clear();
		for(j=0;j<ad.size();j++)
		{
			i=ad[j];
			if(book[i]||hav[i]>=n-1)
			{
				continue;
			}
			y=a[i][hav[i]];
			if(book[y]||hav[y]>=n-1)
			{
				continue;
			}
			d=a[y][hav[y]];
			if(d==i)
			{
				flag=false;
				hav[i]++;
				hav[y]++;
				mat--;
				book[i]=true;
				book[y]=true;
				pos.push_back(i);
				pos.push_back(y);
			}
		}
		if(mat<=0)
		{
			cout<<ans<<endl;
			return 0;
		}
		if(flag)
		{
			cout<<-1<<endl;
			return 0;
		}
		ad=pos;
	}
	return 0;
}