#include<bits/stdc++.h>
using namespace std;
signed main(){
  ios::sync_with_stdio(false);
  cin.tie(0); 
  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];
      a[i][j]--;
    }
  }
  
  int ans = 0;
  int now[10005] = {};
  while(1){
    bool used[10005] = {};
    bool all = true;
    for(int i=0;i<n;i++){
      if(now[i]==n-1 || used[i] || used[a[i][now[i]]]) continue;
      int t = a[i][now[i]];
      if(i == a[t][now[t]]){
	used[i] = true;
	used[t] = true;
	now[i]++;
	now[t]++;
	all = false;
      }
    }
    if(all){
      bool ok = true;
      for(int i=0;i<n;i++){
	if(now[i]!=n-1) ok =false;
      }
      if(ok){
	cout << ans << endl;
	return 0;
      }
    cout << -1 << endl;
    return 0;
    }
    ans++;
  }
  return(0);
}
