#include "bits/stdc++.h"
using namespace std;
#define ll long long int
#define rep(i,n) for( int i = 0; i < n; i++ )
#define rrep(i,n) for( int i = n; i >= 0; i-- )
#define REP(i,s,t) for( int i = s; i <= t; i++ )
#define RREP(i,s,t) for( int i = s; i >= t; i-- )
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define INF 2000000000
#define mod 1000000007
#define INF2 1000000000000000000
typedef pair<int, int> P;

int main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N; cin >> N;
    int A[20], B[20];
    rep(i, N) cin >> A[i];
    rep(i, N) cin >> B[i];
    int ans = INF;
    rep(bit2, (1 << N)) {
        vector<P> v1, v1_after;
        vector<P> v2, v2_after;
        vector<P> v, v_after;
        int bit = bit2;
        rep(i, N) {
            if ((i + bit % 2) % 2 == 0) {
                if (bit % 2 == 0) {
                    v1.push_back({A[i], i});
                    v.push_back({A[i], i});
                }
                else {
                    v1.push_back({B[i], i});
                    v.push_back({B[i], i});
                }
            } else {
                if (bit % 2 == 0) {
                    v2.push_back({A[i], i});
                    v.push_back({A[i], i});
                }
                else {
                    v2.push_back({B[i], i});
                    v.push_back({B[i], i});
                }
            }
            bit /= 2;
        }
        //cout << bit2 << endl;
        //cout << v1.size() << " " << v2.size() << endl;
        if (v1.size()!= v2.size() + (N % 2)) continue;
        rep(i, v1.size()) v1_after.push_back(v1[i]);
        rep(i, v2.size()) v2_after.push_back(v2[i]);
        sort(v1_after.begin(), v1_after.end());
        sort(v2_after.begin(), v2_after.end());
        bool ok = true;
        
        rep(i, N / 2) {
            v_after.push_back(v1_after[i]);
            v_after.push_back(v2_after[i]);
        }
        if (N % 2 == 1) v_after.push_back(v1_after[(int)v1_after.size() - 1]);
        //cout << bit2 << endl;
        //rep(i, v2.size()) cout << "*" << v2_after[i];
        //cout << endl;
        rep(i, v_after.size() - 1) {
            if (v_after[i].first > v_after[i + 1].first) ok = false;
            //cout << v_after[i].first << " ";
        }
        // cout << v_after[v_after.size() - 1].first<< " ";
        // cout << endl;
        // cout << "ok:" << ok << endl;
        if(!ok) continue;
        int cnt = 0;
        vector<int> order;
        rep(i, v_after.size()) order.push_back(v_after[i].second);
        //rep(i, order.size()) cout << order[i] << " ";
        //cout << "->" << cnt << endl;
        for (int i = 0; i < order.size(); i++) {
            for (int j = 0; j < (int)order.size() - 1; j++) {
                if (order[j] > order[j + 1]) {
                    cnt++;
                    swap(order[j], order[j + 1]);
                }
            }
            //rep(i, order.size()) cout << order[i] << " ";
            //cout << "->" << cnt << endl;
        }
        //cout << "cnt:" << cnt << endl;
        ans = min(ans, cnt);

    }
    if (ans == INF) {
        cout << -1 << endl;
    } else {
        cout << ans << endl;
    }

    return 0;
}


Measured memory_bytes: 256