#include<iostream>
using namespace std;
int main() {
  int N;
  cin >> N;
  int A[1000][1000];
  for (int i = 0;i < N;++ i) for (int j = 0;j < N - 1;++ j) {
    cin >> A[i][j];
    -- A[i][j];
  }
  int battle[1000], fight[1000];
  for (int i = 0;i < N;++ i) battle[i] = fight[i] = 0;
  int day = 0, match = N * (N - 1);
  do {
    int check = match;
    ++ day;
    for (int i = 0;i < N;++ i) {
      if (battle[i] >= N - 1) {
        fight[i] = day;
        continue;
      }
      int opponent = A[i][battle[i]];
      if (opponent < i && fight[opponent] < day && A[opponent][battle[opponent]] == i) {
        match -= 2;
        ++ battle[i];
        ++ battle[opponent];
        fight[i] = fight[opponent] = day;
      }
    }
    if (check == match) {
      cout << -1 << endl;
      return 0;
    }
  } while(match > 0);
  cout << day << endl;
  return 0;
}