#include <iostream>
#include<algorithm>
#include<limits.h>
using namespace std;

int main() {
	short N, **a, n[1000] = {}, enemy, fin = 0, match = 0;
	int last_m[1000] = {};
	cin >> N;
	a = (short**)malloc(sizeof(short*) * N);
	for (int i = 0; i < N; i++)
		a[i] = (short*)malloc(sizeof(short) * (N - 1));
	for (int i = 0; i < N; i++) {
		for (int j = 0; j < N - 1; j++) {
			cin >> a[i][j];
			a[i][j]--;
		}
	}
	for (int day = 1;; day++) {
		match = 0;
		for (int i = 0; i < N; i++) {
			if (last_m[i] == day)
				continue;
			if (n[i] == N - 1)
				continue;
			enemy = a[i][n[i]];
			if (a[enemy][n[enemy]] == i && last_m[enemy] != day) {
				if (++n[i] == N - 1)
					fin++;
				else
					last_m[i] = day;
				if (++n[enemy] == N - 1)
					fin++;
				else
					last_m[enemy] = day;
				match++;
			}
		}
		if (fin == N) {
			cout << day << endl;
			return 0;
		}
		if (!match) {
			cout << -1 << endl;
			return 0;
		}
	}
	return 0;
}