#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define mod 1000000007

int main(){
    ll n;
    cin >> n;
    n *= 2;
    vector <ll> v(n);
    for(ll i = 0;i<n;i++) cin >> v[i];
    vector <ll> temp1,temp2,temp;
    for(ll i = 0;i<n;i++) {
        temp1.push_back(i+1);
        temp2.push_back(i+1);
        temp.push_back(i+1);
    }
    if(v == temp1) {
        cout << 0 << endl;
        return 0;
    }
    ll cnt1 = 1, cnt2 = 1;
    ll ans = 0,flag = 1;
    while(true){
        if(cnt1%2 == 1){
            for(ll i = 0;i<n;i+=2){
                swap(temp1[i],temp1[i+1]);
            }
        }
        else{
            for(ll i = 0;i<n/2;i++){
                swap(temp1[i],temp1[n/2+i]);
            }
        }
        if(cnt2%2 == 1){
            for(ll i = 0;i<n/2;i++){
                swap(temp2[i],temp2[n/2+i]);
            }
        }
        else{
            for(ll i = 0;i<n;i+=2){
                swap(temp2[i],temp2[i+1]);
            }
        }
        cnt1++;
        cnt2++;
        ans++;
        if(temp1 == temp && temp2 == temp) {
            flag = 0;
            break;
        }
        if(temp1 == v || temp2 == v){
            break;
        }
    }
    if(flag == 0) cout << -1 << endl;
    else cout << ans << endl;
}