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. 
import java.io.*;
import java.util.*;
import java.lang.Math;

public class Main{
	static BufferedReader reader;
	static StringTokenizer tokenizer;
	static PrintWriter writer;

	static int nextInt() throws IOException {
		return Integer.parseInt(nextToken());
	}

	static long nextLong() throws IOException {
		return Long.parseLong(nextToken());
	}

	static double nextDouble() throws IOException {
		return Double.parseDouble(nextToken());
	}

	static String nextToken() throws IOException {
		while (tokenizer == null || !tokenizer.hasMoreTokens()) {
			tokenizer = new StringTokenizer(reader.readLine());
		}
		return tokenizer.nextToken();
	}
	static String nexts() throws IOException {
	  	  tokenizer = new StringTokenizer(reader.readLine());
	   	 String s="";
	   	 while (tokenizer.hasMoreTokens()) {
			s+=tokenizer.nextElement()+" ";
		}
		return s;
	}
	public static int gcd(int x, int y){
		if (y == 0) return x; else return gcd(y, x % y);
	}

	public static boolean isPrime(int nn) 
	    { 
	         if(nn<=1){
		 return false; }
	        if(nn<=3){
		 return true; }
	      if (nn%2==0||nn%3==0){
		 return false; }
	        for (int i=5;i*i<=nn;i=i+6){ 
	            if(nn%i==0||nn%(i+2)==0){
	            	return false;  }
	            }
	         return true; 
	    } 

	public static void shuffle(int[] A) {
		for (int i = 0; i < A.length; i++) {
			int j = (int)(i * Math.random());
			int tmp = A[i];
			A[i] = A[j];
			A[j] = tmp;
		}
	}
	public static void shufflel(Long[] A) {
		for (int i = 0; i < A.length; i++) {
			int j = (int)(i * Math.random());
			long tmp = A[i];
			A[i] = A[j];
			A[j] = tmp;
		}
	}

	public static String reverse(String input)
 	   {
	        StringBuilder input2=new StringBuilder();
	        input2.append(input);
	        input2 = input2.reverse();
	        return input2.toString();
	    }


	 public static long power(int x, long n)
	{
	//    long mod = 1000000007;
		if (n == 0) {
			return 1;
		}

		long pow = power(x, n / 2);

		if ((n & 1) == 1) {
			return (x * pow * pow);
		}
		return (pow * pow);
	}
	public static long power(long x, long y, long p)     //x^y%p
	    { 
  	       long res = 1; 
	       x = x % p; 
  	       while (y > 0) { 
 	 	 if (y % 2 == 1) {
      	        	        res = (res * x) % p; 
		 }
  		 y = y >> 1; // y = y/2 
     	     	 x = (x * x) % p; 
     	         } 
  	         return res; 
    	} 

	 static long ncr(int n, int k)  
   	 { 
           		 long res = 1; 
  		   // Since C(n, k) = C(n, n-k)  
 		       if (k > n - k) { 
     		       k = n - k; 
      		  } 
  		  // Calculate value of [n*(n-1)*---*(n-k+1)] / [k*(k-1)*---*1]  
     		   for (int i = 0; i < k; ++i) { 
        		    res *= (n - i); 
         		   res /= (i + 1); 
     		   } 
  		  return res; 
 	   }
	public static int inv(int a, int m)     //Returns modulo inverse of a with respect to m using extended euclid algorithm
	    { 
	        int m0=m,t,q; 
	        int x0=0,x1=1; 
      	        if(m==1){
	                return 0; }
                 	         while(a>1) 
     	        {  
   	                q=a/m; 
    	                t=m; 
                                 m=a%m;a=t; 
    	                t=x0; 
     	                x0=x1-q*x0; 
      	                x1=t; } 
    	          if(x1<0){
 	   	 x1+=m0; }
   	           return x1; 
	    } 

	static int modInverse(int n, int p) 
  	{ 
    	          return (int)power((long)n, (long)(p - 2),(long)p); 
	 } 
	static int ncrmod(int n, int r, int p) 
   	 { 
	        if (r == 0)        // Base case 
	            return 1; 
  	        int[] fac = new int[n + 1];         // Fill factorial array so that we can find all factorial of r, n and n-r 
	        fac[0] = 1; 
	        for (int i = 1; i <= n; i++) 
                                     fac[i] = fac[i - 1] * i % p; 
   	         return (fac[n] * modInverse(fac[r], p) % p * modInverse(fac[n - r], p) % p) % p;     //IMPORTANT
    	}	 

	static int lower(int a[], int x)   //Returns rightest index of x in sorted arr else -1
  	  {                                                //If not present returns index of just smaller element
  	            int n=a.length;
    	        int l=0;
                int r=n-1;
                int ans=-1;
                while(l<=r){
                    int m=(r-l)/2+l;
                    if(a[m]<=x){
                        ans=m;
                        l=m+1;
                    }
                    else{
                        r=m-1;
                    }
                }
                 return ans;  
                } 
	static int upper(int a[], int x)     //Returns leftest index of x in sorted arr else n
 	   {                                                  //If not present returns index of just greater element
 	            int n=a.length;
   	            int l=0;
                int r=n-1;
                int ans=n;
                while(l<=r){
                    int m=(r-l)/2+l;
                    if(a[m]>=x){
                        ans=m;
                        r=m-1;
                    }
                    else{
                         l=m+1;
                    }
                }
                 return ans; 
                 } 

	public static long stringtoint(String s){ // Convert bit string to number
		long a = 1;
		long ans = 0;
		StringBuilder sb = new StringBuilder();
		sb.append(s);  
		sb.reverse();
		s=sb.toString();
		for(int i=0;i<s.length();i++){
			ans = ans + a*(s.charAt(i)-'0');
			a = a*2;
		}
		return ans;
	}
	public static boolean ok(int[] a, int n){
	    for(int i=1;i<n;i++)
	{
		if(a[i]<a[i-1])return false;
	}
	return true;
	}
 	public static void op1(int[] a){
	    int n=a.length;
	    for(int i=0;i<n;i++){
	        int t=a[i];
	        a[i]=a[i+1];
	        a[i+1]=t;
	        i++;
	        //i++;
	    }
	}
	public static void op2(int[] a){
	    int n=a.length/2;
	    for(int i=0;i<n;i++){
	        int t=a[i];
	        a[i]=a[i+n];
	        a[i+n]=t;
	       // i++;
	    }
	}
	String inttostring(long a,long m){        // a is number and m is length of string required
		String res = "";                     // Convert a number in bit string representation
		for(int i=0;i<(int)m;i++){
			if((a&(1<<i))==1){
				res+='1';
			}else
				res+='0';
		}
		StringBuilder sb = new StringBuilder();
		sb.append(res);  
		sb.reverse();
		res=sb.toString();
		return res;
    }
	
	 static class R implements Comparable<R>{
	        int x, y;
	        public  R(int x, int y) {           //a[i]=new R(x,y);
	            this.x = x;
	            this.y = y;
	        }
	        public int compareTo(R o) {
            		return x-o.x;     //Increasing order(Which is usually required)
        		}
	    }   
/*   FUNCTION TO SORT HASHMAP ACCORDING TO VALUE
//USE IT AS FOLLOW	

//Make a new list
List<Map.Entry<Integer, Integer> > list = 
               new LinkedList<Map.Entry<Integer, Integer> >(h.entrySet()); 
  
        // Sort the list 
        Collections.sort(list, new Comparator<Map.Entry<Integer, Integer> >() { 
            public int compare(Map.Entry<Integer, Integer> o1,  
                               Map.Entry<Integer, Integer> o2) 
            { 
                return (o1.getValue()).compareTo(o2.getValue());     //This is used to sort string stored as VALUE, use below function here accordingly
            } 
        }); 
          
        // put data from sorted list to new hashmap  
        HashMap<String, Integer> temp = new LinkedHashMap<String, Integer>(); 
        for (Map.Entry<String, Integer> aa : list) { 
            temp.put(aa.getKey(), aa.getValue()); 
        } 
        return temp;   //Now temp is our new sorted hashmap
OR
	for(int i = 0;i<h.size();i++)  //accessing elements from the list made
		{
			int count = list.get(i).getValue();    //Value
			while(count >= 0)
			{
					int key=list.get(i).getKey();  //key
					count -- ;
			}
		}

////////////////////////////////////////////////////////////////////////////////////////
public int compare(Entry<Integer, Integer> o1, Entry<Integer, Integer> o2) 
	{
		if(o1.getValue() != o2.getValue())
			return o1.getValue() > o2.getValue()?1:-1;  //Sorts Value in increasing order
		else if(o1.getValue() == o2.getValue()){
			return o1.getKey() > o2.getKey() ? 1:-1;  //If value equal, then sorts key in increasing order
		}
		
		return Integer.MIN_VALUE;
	}
*/
//Check if palindrome string - System.out.print(A.equals(new StringBuilder(A).reverse().toString())?"Yes":"No");
	public static void main(String[] args) throws IOException {
		reader = new BufferedReader(new InputStreamReader(System.in));
		tokenizer = null;
		writer = new PrintWriter(System.out);
		solve();
		reader.close();
		writer.close();
	}

	private static void solve() throws IOException {
	//	int t = nextInt();
	//	while(t-->0){
			//String s= nextToken();
			//String[] s = str.split("\\s+");
			//ArrayList<Integer> ar=new ArrayList<Integer>();
			//HashSet<Integer> set=new HashSet<Integer>();
			//HashMap<Integer,String> h=new HashMap<Integer,String>();
			//R[] a1=new R[n];
			//char[] c=nextToken().toCharArray();

			int n = nextInt();
			//long n = nextLong();

			int[] a=new int[2*n];
			//long[] a=new long[n];
		//	int c=-1;
			for(int i=0;i<2*n;i++){
				a[i]=nextInt();
				
			}
			//shuffle(a);
			//shufflel(a);
			//Arrays.sort(a);
		int[] b=new int[2*n];
		int[] c=new int[2*n];
		for(int i=0;i<2*n;i++){
		    b[i] = a[i];
		    c[i] = a[i];
		}
	
	
	if(ok(a,n*2)){
	    writer.println(0);
	    return;
	}
		
	int ans=-1;
	for(int i=0;i<2*n;i++){
		if(i%2==0){
			op1(b);
			op2(c);
		}else{
			op1(c);
			op2(b);
		}
		if(ok(b,n*2) || ok(c,n*2)){
		    ans=i+1;
		    break;
		}
			
	}

			if(ans==-1){
			    writer.println(-1);
			}
			else{
			    writer.println(ans);
			}
            
            
			
		 }
	//}
}