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.math.*;
import java.util.*;

/*
   author : Multi-Thread
*/
public class A {

	// static int INF = 998244353;
	static int INF = (int) 1e9 + 7;
	static int MAX = Integer.MAX_VALUE;
	static int MIN = Integer.MIN_VALUE;

	public static void main(String[] args) {

		// int test = fs.nextInt();
		int test = 1;

		for (int cases = 0; cases < test; cases++) {

			// solve();
			System.out.println(solve());

		}
	}

	static int solve() {
		int n = fs.nextInt();
		int N = 2 * n;
		int ar1[] = new int[N], ar2[] = new int[N];
		int sortedArray[] = new int[N];
		for (int i = 0; i < N; i++) {
			ar1[i] = ar2[i] = fs.nextInt();
			sortedArray[i] = i + 1;
		}
		HashSet<String> set = new HashSet<String>();
		boolean rs = true;
		int move1 = 0, move2 = 0, counter1 = 0, counter2 = 0;
		while (!Arrays.equals(ar1, sortedArray)) {
			StringBuffer x = new StringBuffer();
			if (rs) {

				for (int i = 0; i < N; i += 2) {
					int temp = ar1[i];
					ar1[i] = ar1[i + 1];
					ar1[i + 1] = temp;
					x.append(ar1[i] + "-");
					x.append(ar1[i + 1] + "-");
				}

			} else {

				for (int i = 0; i < n; i++) {
					int temp = ar1[i];
					ar1[i] = ar1[i + n];
					ar1[i + n] = temp;
					x.append(ar1[i] + "-");
				}

				for (int i = n; i < N; i++) {
					x.append(ar1[i] + "-");
				}
			}
			if (set.contains(x.toString())) {
				move1 = -1;
				break;
			} else {
				set.add(x.toString());
			}
			++counter1;
			rs = !rs;
		}
		rs = false;
		set.clear();
		while (!Arrays.equals(ar2, sortedArray)) {
			StringBuffer x = new StringBuffer();
			if (rs) {

				for (int i = 0; i < N; i += 2) {
					int temp = ar2[i];
					ar2[i] = ar2[i + 1];
					ar2[i + 1] = temp;
					x.append(ar2[i] + "-");
					x.append(ar2[i + 1] + "-");
				}

			} else {

				for (int i = 0; i < n; i++) {
					int temp = ar2[i];
					ar2[i] = ar2[i + n];
					ar2[i + n] = temp;
					x.append(ar2[i] + "-");
				}

				for (int i = n; i < N; i++) {
					x.append(ar2[i] + "-");
				}
			}
			if (set.contains(x.toString())) {
				move2 = -1;
				break;
			} else {
				set.add(x.toString());
			}
			++counter2;
			rs = !rs;
		}
		if (move1 == -1 && move2 == -1)
			return -1;
		if (move1 != -1 && move2 != -1)
			return Integer.min(counter1, counter2);
		if (move1 == -1)
			return counter2;
		return counter1;
	}

	static int _min(int... ar) {
		intSort(ar, true);
		return ar[ar.length - 1];
	}

	static int _max(int... ar) {
		intSort(ar, true);
		return ar[ar.length - 1];
	}

	static void intSort(int[] a, boolean reverse) {
		ArrayList<Integer> al = new ArrayList<Integer>();
		for (int i : a)
			al.add(i);
		Collections.sort(al);
		if (reverse) {
			for (int i = 0; i < a.length; i++)
				a[i] = al.get(a.length - i - 1);
		} else {
			for (int i = 0; i < a.length; i++)
				a[i] = al.get(i);
		}
	}

	static void longSort(long[] a, boolean reverse) {
		ArrayList<Long> al = new ArrayList<>();
		for (long i : a)
			al.add(i);
		Collections.sort(al);
		if (reverse) {
			for (int i = 0; i < a.length; i++)
				a[i] = al.get(a.length - i - 1);
		} else {
			for (int i = 0; i < a.length; i++)
				a[i] = al.get(i);
		}
	}

	public static int[] radixSort(int[] f) {
		return radixSort(f, f.length);
	}

	public static int[] radixSort(int[] f, int n) {
		int[] to = new int[n];
		{
			int[] b = new int[65537];
			for (int i = 0; i < n; i++)
				b[1 + (f[i] & 0xffff)]++;
			for (int i = 1; i <= 65536; i++)
				b[i] += b[i - 1];
			for (int i = 0; i < n; i++)
				to[b[f[i] & 0xffff]++] = f[i];
			int[] d = f;
			f = to;
			to = d;
		}
		{
			int[] b = new int[65537];
			for (int i = 0; i < n; i++)
				b[1 + (f[i] >>> 16)]++;
			for (int i = 1; i <= 65536; i++)
				b[i] += b[i - 1];
			for (int i = 0; i < n; i++)
				to[b[f[i] >>> 16]++] = f[i];
			int[] d = f;
			f = to;
			to = d;
		}
		return f;
	}

	static class Pair {
		int first, second;

		public Pair(int first, int second) {
			this.first = first;
			this.second = second;
		}

		public String toString() {
			return "[" + first + "," + second + "]";
		}
	}

	static class LongPair {
		long first;
		long second;

		LongPair(long a, long b) {
			this.first = a;
			this.second = b;
		}

		public String toString() {
			return "[" + first + "," + second + "]";
		}
	}

	static boolean isPrime(long n) {
		// Corner cases
		if (n <= 1)
			return false;
		if (n <= 3)
			return true;
		if (n % 2 == 0 || n % 3 == 0)
			return false;

		long sq = (long) Math.sqrt(n);
		for (int i = 5; i <= sq; i = i + 6)
			if (n % i == 0 || n % (i + 2) == 0)
				return false;

		return true;
	}

	static class FastReader {
		BufferedReader br;
		StringTokenizer st;

		public FastReader() {
			br = new BufferedReader(new InputStreamReader(System.in));
		}

		String next() {
			while (st == null || !st.hasMoreElements()) {
				try {
					st = new StringTokenizer(br.readLine());
				} catch (IOException e) {
					e.printStackTrace();
				}
			}
			return st.nextToken();
		}

		int nextInt() {
			return Integer.parseInt(next());
		}

		long nextLong() {
			return Long.parseLong(next());
		}

		double nextDouble() {
			return Double.parseDouble(next());
		}

		String nextLine() {
			String str = "";
			try {
				str = br.readLine();
			} catch (IOException e) {
				e.printStackTrace();
			}
			return str;
		}
	}

	static class OutputWriter {
		private final PrintWriter writer;

		public OutputWriter(OutputStream outputStream) {
			writer = new PrintWriter(new BufferedWriter(new OutputStreamWriter(outputStream)));
		}

		public OutputWriter(Writer writer) {
			this.writer = new PrintWriter(writer);
		}

		public void print(Object... objects) {
			for (int i = 0; i < objects.length; i++) {
				if (i != 0)
					writer.print(' ');
				writer.print(objects[i]);
			}
		}

		public void println() {
			writer.print("\n");
		}

		public void printLine(Object... objects) {
			print(objects);
			writer.println();
		}

		public void close() {
			writer.close();
		}

		public void flush() {
			writer.flush();
		}

	}

	private static final FastReader fs = new FastReader();
	private static final OutputWriter out = new OutputWriter(System.out);
}