#include <bits/stdc++.h>
/*
#include<algorithm>
#include<array>
#include<cassert>
#include<cmath>
#include<cstdlib>
#include<functional>
#include<iomanip>
#include<iostream>
#include<map>
#include<numeric>
#include<queue>
#include<set>
#include<stack>
#include<string>
#include<typeinfo>
#include<utility>
#include<vector>
*/
#define int long long int
#define double long double
using namespace std;
#define MOD 1000000007
#define INF 1000000000000000007
const int MAX_N = 1 << 17;
#define REP(i, n) for (int(i) = 0, i##_len = (n); (i) < i##_len; (i)++)
#define REPS(i, x) for (int(i) = 1; (i) <= (int)(x); (i)++)
#define RREP(i, x) for (int(i) = ((int)(x)-1); (i) >= 0; (i)--)
#define RREPS(i, x) for (int(i) = ((int)(x)); (i) > 0; (i)--)
#define FOR(i, a, b) for (int(i) = (a); (i) < (b); (i)++)
#define pb push_back
#define mp make_pair
#define BIT(n) ((int)(1) << (n))
#define ALL(x) (x).begin(), (x).end()
#define debug(x) std::cout << #x << ": " << (x) << std::endl
#define nint int
using namespace std;

int dy[] = {0, 0, 1, -1, 0};
int dx[] = {1, -1, 0, 0, 0};
typedef pair<int, int> pii;
typedef pair<double, double> dop;
template <class T>
bool chmax(T& a, const T& b)
{
    if (a < b) {
        a = b;
        return 1;
    }
    return 0;
}
template <class T>
bool chmin(T& a, const T& b)
{
    if (b < a) {
        a = b;
        return 1;
    }
    return 0;
}
int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }
struct aaa {
    aaa()
    {
        cin.tie(0);
        ios::sync_with_stdio(0);
        cout << fixed << setprecision(20);
    };
} aaaaaaa;

void dpseeker(std::vector<std::vector<int>>& dp, int& n, int bitmask, int size, int last, std::vector<int>& a, std::vector<int>& b)
{
    if (size == 0) {
        for (int i = 0; i < n; i++) {
            int nextmask = (1 << i);
            int val = (abs(i - size) % 2 == 0) ? a[i] : b[i];
            chmin(dp[nextmask][val], (int)0);
            dpseeker(dp, n, nextmask, size + 1, val, a, b);
        }
    } else if (size == n) {
        ;
    } else {
        for (int i = 0; i < n; i++) {
            if ((bitmask & (1 << i)) == (1 << i)) {
                continue;
            }
            int nextmask = (bitmask | (1 << i));
            int val = (abs(i - size) % 2 == 0) ? a[i] : b[i];
            if (val < last) {
                continue;
            }
            int count = 0;
            for (int j = i + 1; j < n; j++) {
                if ((nextmask & (1 << j)) == (1 << j)) {
                    count++;
                }
            }
            if (dp[nextmask][val] < dp[bitmask][last] + count) {
                continue;
            }
            chmin(dp[nextmask][val], dp[bitmask][last] + count);
            dpseeker(dp, n, nextmask, size + 1, val, a, b);
        }
    }
}


signed main()
{
    int n;
    cin >> n;
    std::vector<int> a(n);
    std::vector<int> b(n);
    std::vector<std::vector<int>> dp(((int)1 << n), std::vector<int>(51, MOD));
    for (int i = 0; i < n; i++) {
        cin >> a[i];
    }
    for (int i = 0; i < n; i++) {
        cin >> b[i];
    }
    dpseeker(dp, n, 0, 0, 0, a, b);
    int out = MOD;
    for (int i = 0; i < 51; i++) {
        chmin(out, dp[(1 << n) - 1][i]);
    }
    if (out == MOD) {
        cout << -1 << endl;
    } else {
        cout << out << endl;
    }
    return 0;
}

Measured memory_bytes: 114944