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

// Created by @thesupremeone on 04/04/21
public class KingsTask {
    BufferedReader in;
    BufferedWriter out;
    StringTokenizer st;
    boolean onlineJudge;
    int n;

    int complement(int i, int opt){
        if(opt==1){
            if(i%2==0)
                return i-1;
            else
                return i+1;
        }else{
            if(i<=n)
                return n+i;
            else
                return i-n;
        }
    }

    int perform(int[] arr, int opt){
        int newOpt = -1;
        for (int i = 1; i <= n; i++) {
            int a = opt==1 ? 2*i-1 : i;
            int b = complement(a, opt);
            if(arr[a]==1)
                newOpt = b;
            else if(arr[b]==1)
                newOpt = a;
            int temp = arr[a];
            arr[a] = arr[b];
            arr[b] = temp;
        }
        return newOpt;
    }

    void fillSteps(int[] steps, int i, int last, int count){
        if(steps[i]<count)
            return;
        steps[i] = count;
        if(last==2 || last==-1)
            fillSteps(steps, complement(i, 1), 1, count+1);
        if(last==1 || last==-1)
            fillSteps(steps, complement(i, 2), 2, count+1);
    }
    
    // My Solution
    void solve() throws IOException {
        n = getInt();
        int[] arr = new int[2*n+1];
        for (int i = 1; i <= 2 * n; i++) {
            arr[i] = getInt();
        }
        if(n==1){
            println(String.valueOf(arr[1]==1 ? 0 : 1));
            return;
        }else if(n%2==0){
            int pos1 = -1, pos2 = -1;
            for (int i = 1; i <= 2 * n; i++) {
                if(arr[i]==1)
                    pos1 = i;
                if(arr[i]==2)
                    pos2 = i;
            }
            Set<Integer> set = new HashSet<>();
            set.add(1);
            set.add(2);
            set.add(n+1);
            set.add(n+2);
            if(!set.contains(pos1) || !set.contains(pos2)){
                println("-1");
                return;
            }
        }
        int pos = -1;
        for (int i = 1; i <= 2 * n; i++) {
            if(arr[i]==1)
                pos = i;
        }
        int[] steps = new int[2*n+1];
        Arrays.fill(steps, Integer.MAX_VALUE);
        fillSteps(steps, 1, -1, 0);
        int stepCount = 0;
        while (pos>1){
            int one = complement(pos, 1);
            int two = complement(pos, 2);
            if(steps[one]<=steps[two]){
                pos = perform(arr, 1);
            }else {
                pos = perform(arr, 2);
            }
            stepCount++;
        }
        boolean sorted = true;
        int last = Integer.MIN_VALUE;
        for (int i = 1; i <= 2 * n; i++) {
            if(arr[i]<last){
                sorted = false;
                break;
            }
            last = arr[i];
        }
        if(sorted){
            println(String.valueOf(stepCount));
        }else {
            println("-1");
        }
    }
    // Handling CodeExecution
    public static void main(String[] args) throws Exception {
        new KingsTask().run();
    }
    void run() throws IOException {
        onlineJudge = isOnlineJudge();
        // Defining Input Streams
        if (onlineJudge) {
            in = new BufferedReader(new InputStreamReader(System.in));
            out = new BufferedWriter(new OutputStreamWriter(System.out));
        } else {
            in = new BufferedReader(new FileReader("input.txt"));
            out = new BufferedWriter(new FileWriter("output.txt"));
        }
        // Running Logic
        solve();
        out.flush();
        // Run example test cases
        if (!onlineJudge) {
            BufferedReader output = new BufferedReader(new FileReader("output.txt"));
            BufferedReader answer = new BufferedReader(new FileReader("answer.txt"));
            StringBuilder outFile = new StringBuilder();
            StringBuilder ansFile = new StringBuilder();
            String temp;
            while ((temp = output.readLine()) != null)
                outFile.append(temp.trim());
            while ((temp = answer.readLine()) != null)
                ansFile.append(temp.trim());
            if (outFile.toString().equals(ansFile.toString()))
                System.out.println("Test Cases Passed!!!");
            else
                System.out.println("Failed...");
        }
    }
    // Checks whether the code is running on OnlineJudge or LocalSystem
    boolean isOnlineJudge() {
        try {
            return System.getProperty("ONLINE_JUDGE")!=null
                    || System.getProperty("LOCAL")==null;
        } catch (Exception e) {
            return true;
        }
    }
    // Some functions
    void print(String... s) throws IOException {
        for (String value : s) out.write(value);
    }
    void println(String... s) throws IOException{
        print(s);
        out.newLine();
    }
    String getLine() throws IOException{
        return in.readLine();
    }
    String getToken() throws IOException{
        if(st==null || !st.hasMoreTokens())
            st = new StringTokenizer(getLine());
        return st.nextToken();
    }
    int getInt() throws IOException {
        return Integer.parseInt(getToken());
    }
    long getLong() throws IOException {
        return Long.parseLong(getToken());
    }
    int[] getInts(int n) throws IOException {
        int[] a = new int[n];
        for (int i = 0; i < n; i++)
            a[i] = getInt();
        return a;
    }
    long[] getLongs(int n) throws IOException {
        long[] a = new long[n];
        for (int i = 0; i < n; i++)
            a[i] = getLong();
        return a;
    }
    int[][] getIntMat(int n, int m) throws IOException {
        int[][] mat = new int[n][m];
        for (int i = 0; i < n; i++)
            for (int j = 0; j < m; j++)
                mat[i][j] = getInt();
        return mat;
    }
    char[][] getCharMat(int n, int m) throws IOException {
        char[][] mat = new char[n][m];
        for (int i = 0; i < n; i++) {
            String s = getLine();
            for (int j = 0; j < m; j++)
                mat[i][j] = s.charAt(j);
        }
        return mat;
    }
}