We have N cards numbered 1, 2, ..., N. Card i (1 \leq i \leq N) has an integer A_i written in red ink on one side and an integer B_i written in blue ink on the other side. Initially, these cards are arranged from left to right in the order from Card 1 to Card N, with the red numbers facing up.

Determine whether it is possible to have a non-decreasing sequence facing up from left to right (that is, for each i (1 \leq i \leq N - 1), the integer facing up on the (i+1)-th card from the left is not less than the integer facing up on the i-th card from the left) by repeating the operation below. If the answer is yes, find the minimum number of operations required to achieve it.

* Choose an integer i (1 \leq i \leq N - 1). Swap the i-th and (i+1)-th cards from the left, then flip these two cards.

Constraints

* 1 \leq N \leq 18
* 1 \leq A_i, B_i \leq 50 (1 \leq i \leq N)
* All values in input are integers.

Input

Input is given from Standard Input in the following format:


N
A_1 A_2 ... A_N
B_1 B_2 ... B_N


Output

If it is impossible to have a non-decreasing sequence, print `-1`. If it is possible, print the minimum number of operations required to achieve it.

Examples

Input

3
3 4 3
3 2 3


Output

1


Input

2
2 1
1 2


Output

-1


Input

4
1 2 3 4
5 6 7 8


Output

0


Input

5
28 15 22 43 31
20 22 43 33 32


Output

-1


Input

5
4 46 6 38 43
33 15 18 27 37


Output

3
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.StringTokenizer;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        FastScanner in = new FastScanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        ProblemD_SwapAndFlip solver = new ProblemD_SwapAndFlip();
        solver.solve(1, in, out);
        out.close();
    }

    static class ProblemD_SwapAndFlip {
        public void solve(int testNumber, FastScanner in, PrintWriter out) {
            int n = in.nextInt();
            int[] a = new int[n];
            for (int i = 0; i < n; i++) {
                a[i] = in.nextInt();
            }
            int[] b = new int[n];
            for (int i = 0; i < n; i++) {
                b[i] = in.nextInt();
            }

            int max = 0;
            for (int x : a) {
                max = Math.max(max, x);
            }
            for (int x : b) {
                max = Math.max(max, x);
            }

            final int infinity = (int) 1e9;
            int[][] d = new int[max + 1][1 << n];
            for (int[] arr : d) {
                Arrays.fill(arr, infinity);
            }
            d[0][0] = 0;
            int[] cost = new int[n];
            for (int mask = 0; mask < 1 << n; mask++) {
                int pos = Integer.bitCount(mask);
                Arrays.fill(cost, 0);
                for (int i = 0; i < n; i++) {
                    if (((mask >> i) & 1) != 0) {
                        continue;
                    }
                    for (int j = 0; j < i; j++) {
                        if (((mask >> j) & 1) != 0) {
                            continue;
                        }
                        ++cost[i];
                    }
                }
                for (int prev = 0; prev <= max; prev++) {
                    for (int i = 0; i < n; i++) {
                        if (((mask >> i) & 1) != 0) {
                            continue;
                        }
                        int nmask = mask | (1 << i);
                        int cur = Math.abs(i - pos) % 2 == 0 ? a[i] : b[i];
                        if (cur < prev) {
                            continue;
                        }
                        d[cur][nmask] = Math.min(d[cur][nmask], d[prev][mask] + cost[i]);
                    }
                }
            }
            int ans = infinity;
            for (int i = 0; i <= max; i++) {
                ans = Math.min(ans, d[i][(1 << n) - 1]);
            }
            if (ans >= infinity) {
                ans = -1;
            }
            out.println(ans);
        }

    }

    static class FastScanner {
        private BufferedReader in;
        private StringTokenizer st;

        public FastScanner(InputStream stream) {
            in = new BufferedReader(new InputStreamReader(stream));
        }

        public String next() {
            while (st == null || !st.hasMoreTokens()) {
                try {
                    String rl = in.readLine();
                    if (rl == null) {
                        return null;
                    }
                    st = new StringTokenizer(rl);
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return st.nextToken();
        }

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

    }
}

