#include <bits/stdc++.h>
using namespace std;

#define lli long long int
#define REP(i,s,n) for(int i=s;i<n;i++)
#define NUM 2520
#define INF (1LL<<50)
#define DEBUG 0
#define mp(a,b) make_pair(a,b)
#define SORT(V) sort(V.begin(),V.end())
#define PI (3.141592653589794)
#define TO_STRING(VariableName) # VariableName
#define LOG(x) if(DEBUG)cout<<TO_STRING(x)<<"="<<x<<" "<<endl;
#define LOG2(x,y) if(DEBUG)cout<<TO_STRING(x)<<"="<<x<<" "<<TO_STRING(y)<<"="<<y<<endl;
#define LOG3(x,y,z) if(DEBUG)cout<<TO_STRING(x)<<"="<<x<<" "<<TO_STRING(y)<<"="<<y<<" "<<TO_STRING(z)<<"="<<z<<endl;
#define LOG4(w,x,y,z) if(DEBUG)cout<<TO_STRING(w)<<"="<<w<<" "<<TO_STRING(x)<<"="<<x<<" "<<TO_STRING(y)<<"="<<y<<" "<<TO_STRING(z)<<"="<<z<<endl;

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; }

lli bitCount(lli num){
    lli rtn = 0;
    while(num>0){
        rtn += num%2;
        num/=2;
    }
    return rtn;
}

 /* https://qiita.com/drken/items/1b7e6e459c24a83bb7fd */
template <class Abel> struct BIT {
    vector<Abel> dat;
    Abel UNITY_SUM = 0;                     // to be set

    /* [1, n] */
    BIT(lli n) { init(n); }
    void init(lli n) {
        dat.resize(n + 1);
        for (lli i = 0; i < (lli)dat.size(); ++i) dat[i] = UNITY_SUM;
    }

    /* a is 1-indexed */
    inline void add(lli a, Abel x) {
        for (lli i = a; i < (lli)dat.size(); i += i & -i)
            dat[i] = dat[i] + x;
    }

    /* [1, a], a is 1-indexed */
    inline Abel sum(lli a) {
        Abel res = UNITY_SUM;
        for (lli i = a; i > 0; i -= i & -i)
            res = res + dat[i];
        return res;
    }

    /* [a, b), a and b are 1-indexed */
    inline Abel sum(lli a, lli b) {
        return sum(b - 1) - sum(a - 1);
    }

    /* k-th number (k is 0-indexed) */
    lli get(long long k) {
        ++k;
        lli res = 0;
        lli N = 1; while (N < (lli)dat.size()) N *= 2;
        for (lli i = N / 2; i > 0; i /= 2) {
            if (res + i < (lli)dat.size() && dat[res + i] < k) {
                k = k - dat[res + i];
                res = res + i;
            }
        }
        return res + 1;
    }
};

void func(long long N, std::vector<long long> A, std::vector<long long> B){

    lli ans = INF;
    REP(bit,0,(1LL<<N)){
        //if(bitCount(bit)%2!=0)continue;
        vector<lli> c(N),d(N);
        vector<pair<lli,lli>> odd,even;
        REP(i,0,N){
            if(bit&(1LL<<i)){
                c[i] = B[i];
                if(i%2==0)odd.push_back({c[i],i});
                else even.push_back({c[i],i});
            }
            else {
                c[i] = A[i];
                if(i%2==0)even.push_back({c[i],i});
                else odd.push_back({c[i],i});
            }
            d[i] = c[i];
        }

        // 遷移先が偶数になるものは (N + 1) / 2 枚、奇数は N / 2 枚
        if (!((even.size() == (N + 1) / 2) && (odd.size() == N / 2))) {
            continue;
        }
        // 偶奇で分けてソート
        SORT(even);
        SORT(odd);
        // 全体として広義単調増加か確認
        vector<pair<int, int>> whole;
        REP(i,0, N) {
            if (i % 2 == 0) {
                whole.push_back(even[i / 2]);
            } else {
                whole.push_back(odd[i / 2]);
            }
        }
        bool flag = false;
        REP(i,0, N - 1) {
            if (whole[i].first > whole[i + 1].first) {
                flag = true;
                break;
            }
        }
        if (flag) {
            continue;
        }
        // 転倒数の計算（もとの並び方に戻して計算する）
        int t = 0;
        for (int i = 0; i < N - 1; i++) {
            for (int j = 0; j < N - i - 1; j++) {
                if (whole[j].second > whole[j + 1].second) {
                    swap(whole[j], whole[j + 1]);
                    t++;
                }
            }
        }
        chmin(ans, (lli)t);

    }

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



}

int main(){
    // cout << fixed << setprecision(5);

    long long N;
    scanf("%lld",&N);
    std::vector<long long> A(N);
    for(int i = 0 ; i < N ; i++){
        scanf("%lld",&A[i]);
    }
    std::vector<long long> B(N);
    for(int i = 0 ; i < N ; i++){
        scanf("%lld",&B[i]);
    }
    func(N, std::move(A), std::move(B));
    return 0;
}


Measured memory_bytes: 256