#include<bits/stdc++.h>
using namespace std;
const int maxn = 1e3+10;
int main()
{
	int n;
	int a[maxn][maxn]={};
bool vis[maxn]={};
int  now[maxn]={};
	scanf("%d",&n);
	for(int i=1;i<maxn;i++)now[i]=1;
	for(int i=1;i<=n;i++)
	{
		for(int j=1;j<=n-1;j++)
		{
			scanf("%d",&a[i][j]);
		}
	}
	int day = 0;
    int round = n*(n-1)/2;
    while(round)
    {   for(int i=1;i<=n;i++)
        {
    	    if(now[i]<=n-1)
    	    {
    	    	int b=a[i][now[i]];
    	    	vis[i]=(a[b][now[b]]==i);
			}
	    }
	    int fn = 0;
	    for(int i=1;i<=n;i++)
	    {
	    	if(vis[i])
	    	{
	    		fn++;
	    		now[i]++;
			}
			vis[i]=false;
		}
		if(!fn)
		{
			day=-1;
			break;
		}
		else
		{
			round-=fn/2;
			day++;
		}
	}
	printf("%d\n",day);
	return 0;
}