The brave Knight came to the King and asked permission to marry the princess. The King knew that the Knight was brave, but he also wanted to know if he was smart enough. So he asked him to solve the following task.

There is a permutation p_i of numbers from 1 to 2n. You can make two types of operations. 

  1. Swap p_1 and p_2, p_3 and p_4, ..., p_{2n-1} and p_{2n}. 
  2. Swap p_1 and p_{n+1}, p_2 and p_{n+2}, ..., p_{n} and p_{2n}. 



The task is to find the minimal number of operations required to sort the given permutation.

The Knight was not that smart actually, but quite charming, so the princess asks you to help him to solve the King's task.

Input

The first line contains the integer n (1≤ n≤ 1000). The second line contains 2n integers p_i — the permutation of numbers from 1 to 2n.

Output

Print one integer — the minimal number of operations required to sort the permutation. If it is impossible to sort the permutation using these operations, print -1.

Examples

Input


3
6 3 2 5 4 1


Output


3


Input


2
3 4 2 1


Output


-1


Input


4
1 2 3 4 5 6 7 8


Output


0

Note

In the first example, you can sort the permutation in three operations: 

  1. Make operation 1: 3, 6, 5, 2, 1, 4. 
  2. Make operation 2: 2, 1, 4, 3, 6, 5. 
  3. Make operation 1: 1, 2, 3, 4, 5, 6. 
#include <bits/stdc++.h>
#include <string>
using namespace std;


//---------------------------------------------Debug---------------------------------------------------------------------
void __print(int x) {cerr << x;}
void __print(long x) {cerr << x;}
void __print(long long x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}

template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}


// ---------------------------------------------------------Defines----------------------------------------------------------
#define PI               2*acos(0.0)
#define mem(a,b)         memset(a, b, sizeof(a))
#define pb(a)            push_back(a)
#define MP               make_pair
#define EPS              10E-10
#define ff               first
#define ss               second
#define mod              1000000007
#define fast_cin         ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define sz(a)            (int)a.size()
#define UNIQUE(v)        (v).erase(unique((v).begin(),(v).end()),(v).end())
#define all(a)           a.begin(),a.end()
#define infinity         0x3f3f3f3f
#define gcd(a, b)        __gcd(a, b)
#define lcm(a, b)        ((a)*((b)/gcd(a,b)))
#define endl             "\n"
#define D(x)            cerr << __LINE__ << ": " << #x << " = " << (x) << '\n'
#define DBG              cerr << __LINE__ << ": Hi" << '\n'
//-----------------------------------------------------------Types-----------------------------------------------------------
typedef long long ll;
typedef double db;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<pii>vii;
typedef vector<pll>vll;

////----------------------Graph Moves----------------
const int fx[]={+1,-1,+0,+0};
const int fy[]={+0,+0,+1,-1};
//const int fx[]={+0,+0,+1,-1,-1,+1,-1,+1};   // Kings Move
//const int fy[]={-1,+1,+0,+0,+1,+1,-1,-1};  // Kings Move
//const int fx[]={-2, -2, -1, -1,  1,  1,  2,  2};  // Knights Move
//const int fy[]={-1,  1, -2,  2, -2,  2, -1,  1}; // Knights Move
/*------------------------------------------------*/

/*-----------------------Bitmask------------------*/
ll Set(ll &N, ll pos) {return N = N | (1 << pos);}
ll reset(ll &N, ll pos) {return N = N & ~(1 << pos);}
bool check(ll N, ll pos) {return (bool)(N & (1 << pos));}
/*------------------------------------------------*/

void init() {
#ifndef ONLINE_JUDGE
#define debug(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define debug(x...)
#endif
    fast_cin;
// #ifndef ONLINE_JUDGE
//     freopen("input.txt", "r", stdin);
//     freopen("output.txt", "w", stdout);
// #endif
}

// bool isPrime ( ll n ) {
//     if ( n <= 1 ) return false;
//     int sqrtn = sqrt(n);
//     for ( ll i = 2; i <= sqrtn; i++ ) {
//         if ( n % i == 0 ) return false;
//     }
//     return true;
// }


void Binary(ll x)
{
    for (int  i = 32; i >= 0; i--) {
        if ((1 << i)&x)cerr << "1";
        else cerr << "0";
    }
    cerr << "\n";
}
bool cmp(const pair<int, int> &a,
         const pair<int, int> &b)
{
    return (a.second > b.second);
}

ll ncr(int n,int r){
	// (n-1)ck + (n-1)c(k-1) = nck;
   	ll ans = 1;
   	if(r > n-r)r = n-r;
   	for(ll i = 1;i<=r;i++){
   		ans*=(n-i+1), ans/=i;
   	}return ans;
}

ll pow(ll a, ll b) {
    ll res = 1;
    while (b > 0) {
        if (b & 1)res = (res * a) % mod;
        b >>= 1;
        a = (a * a) % mod;
    }
    return res;
}

void f(int op, vi &v){
	if(op){
		int n = sz(v)/2;
		for(int i = 0;i<n;i++)swap(v[i], v[i+n]);
	}
	else if(!op){
		int n = sz(v);
		for(int i =0;i<n;i+=2)swap(v[i], v[i+1]);
	}
}

const int mxn = 1001;
void solve(){
	int n;
	cin >> n;
	vi v(2*n);
	for(int i =0;i<2*n;i++){
		cin >> v[i];
	}

	int ans = 0; 
	vi a = v, b = v;
	for(int i = 0;i<=2*n;i++){
		// debug(a);
		// debug(b);
		if(is_sorted(all(a)))break;
		if(is_sorted(all(b)))break;
		ans++;
		f(i&1,a);
		f(~i&1,b);
	}
	cout << (ans <=2*n ? ans : -1) << endl;

}		


int main() {
    init();
	// int tc = 1;
	// cout << "Case " << tc++ << ": ";
    int t;t=1;
    while (t--) {
        solve();
    }
    return 0;
}
 