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 <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>

using namespace std;
//using namespace __gnu_pbds;


#define st first
#define nd second
#define pb push_back
#define popb pop_back
#define mp make_pair
#define all(x) x.begin(),x.end()
#define sortall(x) sort(all(x));
#define deb(x) cout << #x << " = " << x << endl
#define debv(x) cout << #x << ": "; for (int i = 0; i < (x).size(); i++) cout << (x)[i] << ' '; cout << endl
#define PI 3.1415926535897932384626
#define fastio ios_base::sync_with_stdio(false); cin.tie(); cout.tie(); srand(time(NULL)); cout << fixed << setprecision(9)
typedef pair< int ,int >                pii;
typedef pair< long long, long long >    pll;
typedef vector< pii >                   vii;
typedef vector< pll >                   vll;
typedef long long                       ll;
typedef map< int, int >                 mii;
typedef set< pii >                      sii;
typedef set< int >                      si;
typedef vector< int >                   vi;
typedef vector< ll >                    vl;
typedef long double                     ld;
typedef pair< ld, ld >                  pld;
typedef vector< pld >                   vpld;
typedef unsigned long long              ull;
typedef long long                       ll;

//typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
//ordered_set t;
//t.insert(val);
//t.find_by_order(i) - returns iterator to the i-th element in set
//t.order_of_key(i) - index of value i

const ll mod = 1e9 + 7;                 /// 1 000 000 007
const ll mod2 = 119 << 23 | 1;          /// 998244353
const ll mod3 = 467093870598391;    /// big prime
int inf = 1e9 + 7;
ll INF = 1e16 + 9;

///tagliatelle here
///

ll power (ll x, ll y);
ll inv (ll x);
bool isPrime (ll x);
ll gcd (ll x, ll y);

//================================================================================

const int nax = 2e5 + 13;

void prep(){
}

vi a, b;
int n;

bool check(){
	for(int i = 1; i < 2 * n; i++){
		if(a[i - 1] > a[i]){
			return false;
		}
	}
	return true;
}

void one(){
	for(int i = 0; i < 2 * n; i += 2){
		swap(a[i], a[i + 1]);
	}
}

void two(){
	for(int i = 0; i < n; i++){
		swap(a[i], a[i + n]);
	}
}

int run(int start){
	int ile = start;
	while(true){
		two();
		ile++;
		if(check())
			return ile;
		if(a == b)
			return -1;
		one();
		ile++;
		if(check())
			return ile;
		if(a == b)
			return -1;
	}
}

void solve(){
	cin >> n;
	a.resize(2 * n);
	for(int i = 0; i < 2 * n; i++){
		cin >> a[i];
	}
	if(check()){
		cout << 0 << endl;
		return;
	}
	b = a;
	one();
	if(check()){
		cout << 1 << endl;
		return;
	}
	int ans = run(1);
	if(ans == -1){
		a = b;
		ans = run(0);
		if(ans == -1){
			cout << ans << endl;
			return;
		}else{
			cout << ans << endl;
			return;
		}
	}else{
		a = b;
		int tmp = run(0);
		if(tmp == -1){
			cout << ans << endl;
		}else{
			cout << min(ans, tmp) << endl;
		}
	}

}

int main(){            ///use cin and printf if you wanna see some REAL SPEED
//#ifndef ONLINE_JUDGE
//    freopen("in.in", "r", stdin);
//    freopen("out.txt", "w", stdout);
//#endif
    fastio;
    int T = 1;
    prep();
    //cin >> T;
    for(int i = 1; i <= T; i++){
        //cout << "test number " << i << endl;
        solve();
        //cout << "end" << endl;
    }
    return 0;
}

ll power (ll x, ll y) {
    ll res = 1ll;
    x %= mod;
    if (x == 0)
        return 0;
    while (y > 0) {
        if (y & 1)
            res = (res * x) % mod;
        y = y >> 1ll;
        x = (x * x) % mod;
    }
    return res;
}

bool isPrime (ll x) {
    if (x == 1)
        return false;
    for (ll i = 2ll; i * i <= x; i++) {
        if (x % i == 0)
            return false;
    }
    return true;
}

ll gcd (ll x, ll y) {
    if (!y)
        return x;
    return gcd (y, x % y);
}

/*
    __builtin_popcount
    __builtin_ctz
    __builtin_clz
*/