#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <deque>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <iomanip>
#include <bitset>
#include <set>
#include <map>
#include <stdio.h>
#include <numeric>
#include <cstring>

#define rep(i,n) for (int i = 0; i < (n); i++)
#define rep1(i,n) for (int i = 1; i < (n); i++)
#define FOR(i,a,b) for (int i=(a); i < (b); i++)
#define MOD 1000000007 //10^9+7
using namespace std;
using ll = long long;
using PII = pair<int, int>;
using PLL = pair<ll, ll>;
const int INF = numeric_limits<int>::max();
const ll INFL = numeric_limits<ll>::max();


// 負の数にも対応した % 演算
long long mod(long long val, long long m) {
    long long res = val % m;
    if (res < 0) res += m;
    return res;
}

//greatest common divisor
long long gcd(ll a, ll b) 
{
    if (a % b == 0) {
        return b;
    } else {
        return gcd(b, a % b);
    }
}

//least common multiple
long long lcm(ll a, ll b)
{
    return a / gcd(a, b) * b ;
}

ll factorial(ll n) {
    ll res = 1;
    for (ll i = 1; i <= n; i++) {
        res *= i;
    }
    return res;
}

int main()
{
    int n; cin >> n;
    vector<int> a(n);
    rep(i,n) cin >> a[i];
    const int MAX = 100001;

    vector<int> odd_hist(MAX, 0), even_hist(MAX, 0);
    rep(i,n) {
        if (i & 1) odd_hist[a[i]]++;
        else even_hist[a[i]]++;
    }

    vector<PII> odd, even;
    rep(i,MAX) {
        odd.push_back(PII(odd_hist[i], i));
        even.push_back(PII(even_hist[i], i));
    }
    sort(odd.begin(), odd.end(), greater<PII>());
    sort(even.begin(), even.end(), greater<PII>());

    if (odd[0].second != even[0].second) {
        cout << n - (odd[0].first + even[0].first) << endl;
    }
    else {
        cout << n - max(odd[0].first + even[1].first,
                odd[1].first + even[0].first) << endl;
    }

    return 0;
}

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
#define rep(i, n) for(int i = 0; i < n; i++)
#define REP(i, a, b) for(int i = a; i <= b; i++)
#define all(x) x.begin(), x.end()
#define fi first
#define se second
#define debug(...) cerr<<__LINE__<<" ["<<#__VA_ARGS__<<"]:",debug_out(__VA_ARGS__)
template <typename T> ostream &operator<<(ostream &os, const vector<T> &vec)
{ for (auto v : vec) os << v << ' '; os << '\n'; return os; }
template <typename T1, typename T2> ostream &operator<<(ostream &os, const pair<T1, T2> &pa)
{ os << '(' << pa.first << ',' << pa.second << ')'; return os; }
void debug_out() { cerr << endl; }
template <typename Head, typename... Tail> void debug_out(Head H, Tail... T)
{ cerr << " " << H; debug_out(T...); }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const int INF = (1<<30) - 1;
const ll LINF = (1LL<<60) - 1;

void solve() {
    int n;
    cin >> n;
    queue<int> A[n];
    rep(i, n) {
        rep(_, n - 1) {
            int a;
            cin >> a;
            A[i].push(a-1);
        }
    }
    int ans = 0;
    while(1) {
        bool flag = 1, end = 1;
        vector<int> op(n, -1);
        rep(i, n) {
            if (A[i].empty()) {
                continue;
            } else {
                end = 0;
            }
            op[i] = A[i].front();
            if (op[A[i].front()] == i) {
                A[op[i]].pop();
                A[i].pop();
                flag = 0;
            }
        }
        if (end) break;
        if (flag) {
            cout << -1 << endl;
            return;
        }
        ans++;
    }
    cout << ans << endl;
}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    solve();
    return 0;
}
