#include <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <cstring>
#include <map>
#include <queue>
#include <cmath>
#include <complex> // complex<double> a(1.2 , 2.3);// real(): 1.2, imag()2.3
using namespace std;

#define MOD 1000000007
#define EPS 1e-10
#define ll long long
#define ld long double
#define FOR(i,a,b) for(ll i=(ll)a;i<(ll)b;i++)
#define rep(i,n) FOR(i,0,n)
#define pb push_back
#define mp make_pair
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define rmsame(a) sort(all(a)),a.erase(unique(all(a)), a.end())
#define rmvector(a,b) rep(i,a.size())rep(j,b.size())if(a[i]==b[j]){a.erase(a.begin()+i);i--;break;}
#define first_more_idx(ve, num) upper_bound(all(ve), num)-ve.begin() // idx = first_more_idx(ve,num); if(idx = ve.size()) , then not exist
#define first_lessequal_idx(ve, num) lower_bound(all(ve), num)-ve.begin()
#define pq_pair_tB priority_queue <pair<ll,ll>, vector<pair<ll,ll> > , greater<pair<ll,ll> > >
#define pq_pair_ts priority_queue <pair<ll,ll> > // only sort first param
template<typename X> bool exist(vector<X> vec, X item){return find(all(vec), item)!=vec.end();}
ll gcd(ll a, ll b){if(b==0)return a;return gcd(b,a%b);}
ll lcm(ll a, ll b){return a/gcd(a,b)*b;}
ll power(ll x, ll n){if(n == 0) return 1;return  (n%2)? x*power(x, n-1)%MOD : power(x*x%MOD, n/2);}
ll dx[]={0, 0, -1, 1};
ll dy[]={1, -1, 0, 0};// up,down,left right


ll calcal(vector<ll> finalidx){
    ll ans = 0;
    ll nxtidx = 0;
    while(finalidx.size() != 0){
        rep(i, finalidx.size()){
            if(finalidx[i] == nxtidx){
                finalidx.erase(finalidx.begin() + i);
                ans += i;
                break;
            }
        }
        nxtidx ++;
    }
    return ans;
}







ll FAILFAIL = 10000000;
ll N ;
vector<pair<pair<ll,ll>, ll> > card_cardId;

bool func(pair<pair<ll,ll>, ll> a, pair<pair<ll,ll>, ll> b){
    if(a.first.first == b.first.first){
        return a.second < b.second;
    }
    return a.first.first < b.first.first;
}


ll cal(vector<ll> odd, vector<ll> even){
//    cerr <<"=====================" << endl;
    vector<pair< pair<ll,ll>, ll> > odd_card;
    vector<pair< pair<ll,ll>, ll> > even_card;
    
    rep(i, odd.size()){
        ll idx = odd[i];
        odd_card.pb( card_cardId[idx] );
//        cerr << idx << ":::::::" << card_cardId[idx].first.first << ", " << card_cardId[idx].first.second << endl;
        if((idx % 2) == 1) {
            swap(odd_card[i].first.first, odd_card[i].first.second);
//            cerr << "odd:" << idx << ", swap" ;
        }
//        else{
//            cerr << "odd:" << idx << ", not swap";
//        }
//        cerr << ", choose: " << odd_card[i].first.first << endl;
    }
    
    rep(i, even.size()){
        ll idx = even[i];
//        cerr << idx << ":::::::" << card_cardId[idx].first.first << ", " << card_cardId[idx].first.second << endl;
        even_card.pb(card_cardId[idx]);
        if((idx % 2) == 0) {
            swap(even_card[i].first.first, even_card[i].first.second);
//            cerr << "even:" << idx << ", swap";
        }
//        else{
//            cerr << "even:" << idx << ", swap" ;
//        }
//        cerr << ", choose: " << even_card[i].first.first << endl;
    }

    sort(all(odd_card), func);
    sort(all(even_card), func);
    
    vector<ll> num, finalidx;
    
    rep(i, odd_card.size()){
        num.pb(odd_card[i].first.first);
        finalidx.pb(odd_card[i].second);
        
        if(i != even_card.size()){
            num.pb(even_card[i].first.first);
            finalidx.pb(even_card[i].second);
        }
    }
    
    
    rep(i, (num.size()-1)){
        if(num[i + 1] < num[i]) return FAILFAIL;
    }
    
//    cerr << "vvvvvv" << endl;
//    rep(i, num.size()){
//        cerr << num[i] << " ";
//    }
//    cerr << endl;

    ll ans = calcal(finalidx);
    
    return ans;

}




int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    

    
    cin >> N ;
    vector<ll> A,B;
    rep(i, N){
        ll inp;
        cin >> inp;
        A.pb(inp);
    }
    rep(i, N){
        ll inp;
        cin >> inp;
        B.pb(inp);
    }
    
    
    rep(i,N){
        ll a = A[i];
        ll b = B[i];
        card_cardId.pb( mp(mp(a,b), i) );
    }
    
    ll ans = FAILFAIL;
    rep(i,  (1 << N)){
        vector<ll> odd_idx;
        vector<ll> even_idx;

        rep(j,  N){
            if(i & (1 << j) ){
                even_idx.pb(j);
            }else{
                odd_idx.pb(j);
            }
        }
        
        if(even_idx.size() != (N/2)) continue;
        
        ll res = cal(odd_idx, even_idx);
        
        ans = min(res, ans);
        
    }
    
    if(ans == FAILFAIL) cout << -1 << endl;
    else cout << ans << endl;

    //cout << fixed << setprecision(16) << ans << endl;
    return 0;
}


Measured memory_bytes: 888