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.BufferedReader;
import java.io.BufferedWriter;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.LinkedList;
import java.util.StringTokenizer;
/*
 * Java Input / Output Class using Buffered/ Input Straem
 * Created by @neelbhallabos
 * File Created at: 4/6/2021
 */
public class CF1510K {
	public static BufferedReader sc = new BufferedReader(new InputStreamReader(System.in));
	public static StringTokenizer st;
	public static PrintWriter pw = new PrintWriter(System.out);
	final static boolean debugmode = true;
	public static int k = 7; // for 10^9 + k mods.
	public static long STMOD = 1000000000 + k; // 10^9 + k
 
	public static void main(String[] args) throws IOException {
		int div2n = getInt();
		int[] arr = readArray(div2n * 2);
		if(div2n % 2 == 0) {
			submit(handleEven(arr), true);
		}
		else {
			submit(handleOdd(arr), true);
		}
			
	}
	
	
	public static int handleOdd(int[] arr) {
		LinkedList<Pair> bfs = new LinkedList<>();
		
		bfs.add(new Pair(arr,0, false));
		bfs.add(new Pair(arr,0, true));
		
		while(bfs.size() > 0) {
			Pair next = bfs.removeFirst();
			//System.out.println("got: " + Arrays.toString(next.cr) + " " + next.nsteps);
			if(isSorted(next.cr)) {
				return next.nsteps;
			}
			int[] rotated = next.cr.clone();
			rotate(rotated);
			int[] swapped = next.cr.clone();
			swapAdjacent(swapped);
			
			if(next.nsteps > 1002) {
				return -1;
			}
			
			if(!next.wasRotated) {
				bfs.add(new Pair(rotated, next.nsteps+1, true));
			}
			else {
				bfs.add(new Pair(swapped, next.nsteps+1, false));
			}
		
		}
		return -1;
		
	}
	
	
	public static int handleEven(int[] arr) {
		int[] swapped = arr.clone();
		swapAdjacent(swapped);
		int[] swappedandrotate = arr.clone();
		swapAdjacent(swappedandrotate);
		rotate(swappedandrotate);
		int[] rotate = arr.clone();
		rotate(rotate);
		
		
		if(isSorted(arr)) {
			return 0;
		}
		else if(isSorted(rotate) || isSorted(swapped)) {
			return 1;
		}
		else if(isSorted(swappedandrotate)) {
			return 2;
		}
		else {
			return -1;
		}
	}
	public static boolean isSorted(int[] r) {
		for(int i = 1; i < r.length;i++) {
			if (r[i-1] > r[i]) {
				return false;
			}
		}
		return true;
	}
	
	public static void swapAdjacent(int[] r) {
		for(int i = 0; i < r.length/2;i++) {
			swap(r, 2*i, 2*i+1);
		}
	}
	
	public static void rotate(int[] r) {
		for(int i = 0; i < r.length/2;i++) {
			swap(r, i, (i + r.length/2)%r.length);
		}
	}
	
	public static void swap(int[] a, int l, int r) {
		int tmp = a[l];
		a[l] = a[r];
		a[r] = tmp;
	}
	

	
	public static void setInputFile(String fn) throws IOException {
		sc = new BufferedReader(new FileReader(fn));
	}
 
	public static void setOutputFile(String fn) throws IOException {
		pw = new PrintWriter(new BufferedWriter(new FileWriter(fn)));
	}
 
	public static int GCD(int a, int b) {
		if (b == 0)
			return a;
		return GCD(b, a % b);
	}
 
	public static double log(int k, int v) {
		return Math.log(k) / Math.log(v);
	}
 
	public static long longpower(int a, int b) {
		long[] vals = new long[(int) (log(b, 2) + 2)];
		vals[0] = a;
		vals[1] = a * a;
		for (int i = 1; i < vals.length; i++) {
			vals[i] = vals[i - 1] * vals[i - 1];
		}
		long ans = 1;
		int cindex = 0;
		while (b != 0) {
			if (b % 2 == 1) {
				ans *= vals[cindex];
			}
			cindex += 1;
			b /= 2;
		}
		return ans;
 
	}
 
	public static void debug(String toPrint) {
		if (!debugmode) {
			return;
		}
		pw.println("[DEBUG]: " + toPrint);
	}
 
	public static void submit(int[] k, boolean close) {
		pw.println(Arrays.toString(k));
		if (close) {
			pw.close();
		}
	}
 
	public static void submit(int p, boolean close) {
		pw.println(Integer.toString(p));
		if (close) {
			pw.close();
		}
	}
 
	public static void submit(String k, boolean close) {
		pw.println(k);
		if (close) {
			pw.close();
		}
	}
 
	public static void submit(double u, boolean close) {
		pw.println(Double.toString(u));
		if (close) {
			pw.close();
		}
	}
 
	public static void submit(long lng, boolean close) {
		pw.println(Long.toString(lng));
		if (close) {
			pw.close();
		}
 
	}
 
	public static void submit() {
		pw.close();
	}
 
	public static int getInt() throws IOException {
		if (st != null && st.hasMoreTokens()) {
			return Integer.parseInt(st.nextToken());
		}
		st = new StringTokenizer(sc.readLine());
		return Integer.parseInt(st.nextToken());
	}
 
	public static long getLong() throws IOException {
		if (st != null && st.hasMoreTokens()) {
			return Long.parseLong(st.nextToken());
		}
		st = new StringTokenizer(sc.readLine());
		return Long.parseLong(st.nextToken());
	}
 
	public static double getDouble() throws IOException {
		if (st != null && st.hasMoreTokens()) {
			return Double.parseDouble(st.nextToken());
		}
		st = new StringTokenizer(sc.readLine());
		return Double.parseDouble(st.nextToken());
	}
 
	public static String getString() throws IOException {
		if (st != null && st.hasMoreTokens()) {
			return st.nextToken();
		}
		st = new StringTokenizer(sc.readLine());
		return st.nextToken();
	}
 
	public static String getLine() throws IOException {
		return sc.readLine();
	}
 
	public static int[][] readMatrix(int lines, int cols) throws IOException {
		int[][] matrr = new int[lines][cols];
		for (int i = 0; i < lines; i++) {
			for (int j = 0; j < cols; j++) {
				matrr[i][j] = getInt();
			}
		}
		return matrr;
	}
 
	public static int[] readArray(int lines) throws IOException {
		int[] ar = new int[lines];
		for (int i = 0; i < lines; i++)
			ar[i] = getInt();
		return ar;
	}
	
	static class Pair {
		int[] cr;
		int nsteps;
		boolean wasRotated;
		
		public Pair(int[] c, int n, boolean wr) {
			cr = c.clone();
			nsteps = n;
			wasRotated = wr;
		}
	}
 
}