#include <bits/stdc++.h> 
#define mahadev             ios_base::sync_with_stdio(0);   cin.tie(0);  cout.tie(0);
#define ll                  long long
#define beg(v)              v.begin(),v.end()
#define rep(i,a,b)          for (int i = a; i < b; i++)
#define rep_rev(i,a,b)      for (int i = a; i > b; i--)
#define go(i,sp)            for(auto i=sp.begin();i!=sp.end();i++)
#define vi                  vector<int>
#define mem1(a)             memset(a,-1,sizeof(a))
#define mem0(a)             memset(a,0,sizeof(a))
#define pb                  push_back
#define pb1                 pop_back
#define fr                  first
#define sc                  second
#define pi                  pair<long,long>
#define len                 length()
#define endl                "\n"
#define ump                 unordered_map
const long long INF=1e18;
const int32_t M=1e9+7;
using namespace std;

vector<ll> v1,v2;
ll sorted=0;
ll impossible=0;
ll ct=0;
ll n;

void perform(ll t){
  if(t==1){}
}

void operate(ll t){
  if(is_sorted(v2.begin(), v2.end())){
    sorted=1;
    return;
  }
  if(ct!=0 && v1==v2){
    impossible=1;
    return;
  } 
  ct++;
  if(t==1){
    for(int i=0; i<2*n-1; i+=2){
      ll t=v2[i];
      v2[i] = v2[i+1];
      v2[i+1] = t;
    }
    operate(2);
  }
  else{
    for(int i=0;i<n;i++){
      ll t=v2[i];
      v2[i] = v2[i+n];
      v2[i+n] = t;
    }
    operate(1);
  }
}

void solve(){
  cin >> n;
  rep(i,0,2*n){
    ll x;
    cin >> x;
    v1.pb(x);
    v2.pb(x);
  }
  ll mn=INT_MAX;
  operate(2);
  mn=min(mn,ct);
  ct=0;
  v2=v1;
  operate(1);
  mn=min(mn,ct);
  if(impossible) cout << -1 << endl;
  else if(sorted) cout << mn << endl;
}

int32_t main() 
{
    // mahadev
    // ll t;
    // cin >> t;
    // while(t--)
      solve();
    return 0;
}