#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#include <climits>
#include <cstring>

#define rep(i, m, n) for(int i=int(m);i<int(n);i++)
#define all(c) begin(c),end(c)

template<typename T1, typename T2>
inline void chmin(T1 &a, T2 b) { if (a > b) a = b; }

template<typename T1, typename T2>
inline void chmax(T1 &a, T2 b) { if (a < b) a = b; }

typedef long long int ll;
using ll = long long int;
using ull = long long unsigned int;
using Int = long long int;
using namespace std;
#define INF (1 << 30) - 1
#define INFl (ll)5e15
#define DEBUG 0
#define dump(x)  cerr << #x << " = " << (x) << endl
#define MOD 1000000007


//edit
class Solve {
public:
    Int N;
    vector<Int> A, B;
    vector<vector<Int>> dp;

    // n : last used, mask : used set
    Int rec(Int n, ull mask) {
        if (dp[n][mask] != -1) {
            return dp[n][mask];
        }

        if (__pop_count(mask) == 1) {
            if (mask == (1 << n)) {
                return dp[n][mask] = n;
            } else {
                return dp[n][mask] = INFl;
            }
        }


        Int ret = INFl;
//        for (ull n_mask = (mask - 1) & mask; mask >= 0; mask--) {
//
//        }

        for (int i = 0; i < N; ++i) {
            ull n_mask = mask - (1 << n);
            if (n_mask >> i & 1) {
                Int L, R;

                // abs(__pop(n_mask) - 1 - i)
                if (abs(i + __pop_count(n_mask) + 1) % 2 == 0) {
                    L = A[i];
                } else {
                    L = B[i];
                }

                if (abs(n + __pop_count(n_mask)) % 2 == 0) {
                    R = A[n];
                } else {
                    R = B[n];
                }
                if (L > R) {
                    continue;
                }



                Int cost = 0;

                for (int j = 0; j < n; ++j) {
                    if (!(mask >> j & 1)) {
                        cost++;
                    }
                }

                Int tmp = rec(i, n_mask) + cost;
                chmin(ret, tmp);
            }
        }

        return dp[n][mask] = ret;
    }

    void solve() {
        cin >> N;
        A.resize(N);
        B.resize(N);

        for (int i = 0; i < N; ++i) {
            cin >> A[i];
        }
        for (int i = 0; i < N; ++i) {
            cin >> B[i];
        }

        dp.resize(N, vector<Int>(1 << N, -1));

        Int ans = INFl;
        for (int i = 0; i < N; ++i) {
            Int tmp = rec(i, (1ull << N) - 1);
            chmin(ans, tmp);
        }

        if (ans == INFl) {
            cout << -1 << endl;
            return;
        }

        cout << ans << endl;


    }
};


int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(10);

    Solve().solve();


    return 0;
}


Measured memory_bytes: 39296