#include <iostream>
#include <string>
#include <vector>
#include <list>
#include <map>
#include <queue>
#include <stack>
#include <algorithm>
#include <fstream>
#include <sstream>
#include <iomanip>

using namespace std;

long long MOD = 1000000007;

template<typename T>
void cout_vec(vector<T> &vec){
    for(int i=0; i<vec.size(); i++){
        if (i!=0){
            cout << ' ';
        }
        cout << vec[i];
    }
    cout << endl;
}

template<typename T>
void cout_mat(vector<vector<T>  > &mat){
    for(int i=0; i<mat.size(); i++){
        vector<T> vec = mat[i];
        cout_vec(mat[i]);
    }
}

int judge(vector<int> &even_rev, vector<int> &odd_rev, vector<vector<int> > &card){
    vector<vector<int> > perm_even(0);
    vector<vector<int> > perm_odd(0);
    for(int i=0; i<(int)even_rev.size(); i++){
        if(even_rev[i]==1){
            perm_odd.push_back({card[2*i][1], card[2*i][2]});
        }else{
            perm_even.push_back({card[2*i][0], card[2*i][2]});
        }

        if(i<(int)odd_rev.size()){
            if(odd_rev[i]==1){
                perm_even.push_back({card[2*i+1][1], card[2*i+1][2]});
            }else{
                perm_odd.push_back({card[2*i+1][0], card[2*i+1][2]});
            }
        }
    }
    sort(perm_even.begin(), perm_even.end());
    sort(perm_odd.begin(), perm_odd.end());

    
    for(int i=0; i<(int) odd_rev.size(); i++){
        
        if(perm_even[i][0] <= perm_odd[i][0]){
            if(i+1==(int)perm_even.size())continue;
            if(perm_odd[i][0]<=perm_even[i+1][0]){
                continue;
            }
        }
        return -1;
    }
    vector<vector<int> > new_card(0);
    for(int i=0; i<(int) odd_rev.size(); i++){
        new_card.push_back(perm_even[i]);
        new_card.push_back(perm_odd[i]);
    }
    if((int)odd_rev.size()<(int)even_rev.size()){
        new_card.push_back(perm_even[(int)even_rev.size()-1]);
    }

    int cnt=0;

    for(int i=0; i<(int) new_card.size(); i++){
        for(int j=i+1; j<(int) new_card.size(); j++){
            if(new_card[i][1]>new_card[j][1]){
                cnt++;
            }
        }
    }

    /*
    for(int i=0; i<(int)perm_even.size(); i++){
        cnt+=max(0,2*i-perm_even[i][1]);
    }

    for(int i=0; i<(int)perm_odd.size(); i++){
        cnt+=max(0,2*i+1-perm_odd[i][1]);
    }


    for(int i=0; i<(int)perm_even.size(); i++){
        for(int j=i+1; j<(int)perm_even.size(); j++){
            if(perm_even[i][1]>perm_even[j][1]){
                cnt++;
            }
        }
    }
    for(int i=0; i<(int)perm_odd.size(); i++){
        for(int j=i+1; j<(int)perm_odd.size(); j++){
            if(perm_odd[i][1]>perm_odd[j][1]){
                cnt++;
            }
        }
    }
    */

    //cout << cnt << endl;
    //cout_mat(new_card);

    return cnt;
}

int main(){
    int N;
    cin >> N;
    vector<vector<int> > card(N,vector<int>(3,0));
    for(int i=0; i<N; i++){
        cin >> card[i][0];
        card[i][2]=i;
    }
    for(int i=0; i<N; i++){
        cin >> card[i][1];
    }

    int ans=MOD;
    int num_even=N/2+(N%2);
    int num_odd=N-num_even;
    for(int k=0; k<=num_odd; k++){
        vector<int> even_reversed(num_even, 0);
        for(int j=num_even-k; j<num_even; j++){
            even_reversed[j]=1;
        }

        vector<int> odd_reversed(num_odd, 0);
        for(int j=num_odd-k; j<num_odd; j++){
            odd_reversed[j]=1;
        }

        do{
            vector<int> tmp_odd(num_odd,0);
            copy(odd_reversed.begin(), odd_reversed.end(), tmp_odd.begin());
            do{
                int ret = judge(even_reversed, odd_reversed, card);
                if(ret==-1)continue;
                else{
                    ans=min(ans, ret);
                }
            }while(next_permutation(odd_reversed.begin(), odd_reversed.end()));

        }while(next_permutation(even_reversed.begin(), even_reversed.end()));
    }
    if(ans==(int)MOD){
        cout << -1 << endl;
    }else{
        cout << ans << endl;
    }
}

Measured memory_bytes: 256