#include "bits/stdc++.h"
using namespace std;

#define mp make_pair
#define pb push_back
#define ll long long int
#define ld long double
#define sd(x) scanf("%lld",&x)
#define inf 1e18+9
#define pll pair<ll,ll>
#define fastio ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define test() int test;cin>>test;while(test--)

clock_t time_p = clock();
void time_taken()
{
    time_p = clock() - time_p;
    cerr << "Time Taken : " << (float)(time_p) / CLOCKS_PER_SEC << "\n";
}


inline ll GCD(ll x, ll y) {
	if(x < 0) x=-x;
	if(y< 0) y=-y;
	if(x>y) swap(x,y);
	if(x==0) return y;
	if(y==0) return x;
	return GCD(x,y%x);
}

inline ll getDigSum(ll x) {
	ll sum = 0;
	while(x) {
		sum += x%10;
		x/=10;
	}
	return sum;
}

ll mul(ll x, ll y, ll mod) {
	ll ans = ((x*y)%mod+mod)%mod;
	return ans;
}

bool checkSorted(vector<int> &v, int n) {
	for(int i=1;i<n;i++) {
		if(v[i-1]>=v[i]) return false;
	}
	return true;
}

void doOperation(vector<int> &v, int n, int op) {
	if(op==1) {
		for(int i=0;i<n-1;i+=2) {
			swap(v[i],v[i+1]);
		}
	} else {
		for(int i=0;i+(n/2)<n;i++) {
			swap(v[i],v[i+(n/2)]);
		}
	}
}


int main() {
	fastio;

	int n;
	cin>>n;	

	n*=2;

	vector<int> v(n);
	for(int i=0;i<n;i++) {
		cin>>v[i];
	}

	vector<int> dum = v;

	if(checkSorted(v,n)) {
		cout<<0<<endl;
		return 0;
	}

	int ans1=0;
	int op=1;
	int c1 = 0, c2 = 0;
	for(int i=1;i<=n;i++) {
		doOperation(v,n,op++%2);
		ans1++;
		if(checkSorted(v,n)) {
			c1=1;
			break;
		}
	}

	int ans2 = 0;
	op = 0;
	v = dum;
	for(int i=1;i<=n;i++) {
		doOperation(v,n,op++%2);
		ans2++;
		if(checkSorted(v,n)) {
			c2=1;
			break;
		}
	}

	if(c1 || c2) {
		int ans = min(ans1,ans2);
		cout<<ans<<endl;
	} else cout<<-1<<endl;

}



