//2019年12月8日現在

#include<stdio.h>
#include<cmath>
#include<math.h>
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<complex>
#include<queue>
#include<set>
#include<utility>
#include<iomanip>
#include<limits>
#include<thread>
#include<map>
#include<stack>
#include<numeric>
#include<cassert>
#include<random>
#include<chrono>
#include<unordered_set>
#include<unordered_map>
#include<fstream>
#include<list>
#include<functional>
#include<bitset>
#include<tuple>
#include <cstdio>

using namespace std;

template <class... A>
void prints() { cout << "\n"; }
template <class... A>
void prints_rest() { cout << "\n"; }
template <class T, class... A>
void prints_rest(const T &first, const A &... rest) { cout << " " << first; prints_rest(rest...); }
template <class T, class... A>
void prints(const T &first, const A &... rest) { cout << first; prints_rest(rest...); }

namespace {
    // printElms(&a[0], a[n]);　みたいな感じで使う。
    void printElems(const int* begin, const int* end)
    {
        for (const int* p = begin; p != end; ++p) {
            std::cout << *p << ' ';
        }
        std::cout << std::endl;
    }
}



#define rep(i,n) for(int i=0; i<n; i++)
#define rep1(i,n) for(int i=1; i<n+1; i++)
#define repr(i,n) for(int i=n-1; i>=0; i--)
#define repr1(i,n) for(int i=n; i>0; i--)
#define souatari rep1(i,n-1)rep(j,i)
#define souatari1 for(int i=2; i<n+1; i++)rep1(j,i-1)
#define mp make_pair
#define F first
#define S second
#define elif else if

typedef long long ll;
typedef vector<int>  vi;
typedef vector<vi>  vvi;
typedef vector<ll> vll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<pii> vpii;
typedef array<int,3> arr3;
typedef long double D;


const ll llinf =  numeric_limits<ll>::max();
const ll _llinf = numeric_limits<ll>::lowest();
const int inf = numeric_limits<int>::max();
const int _inf = numeric_limits<int>::lowest();
const double dinf = numeric_limits<double>::infinity();
const ll MOD = 1000000007;
const ll BIG = 10000000000000000;


int a[20];
int b[20];

int main(){
    int n;
    cin >> n;
    rep1(i,n) cin >> a[i];
    rep1(i,n) cin >> b[i];

    int fans = inf;


    int nownf = 0;
    bool flag = false;
    rep1(i,n){
        if(nownf>a[i]){
            flag = true;
            break;
        }
        else{
            nownf = a[i];
        }
    }

    if(!flag) {
        prints(0);
        return 0;
    }

    int stoppoint = pow(2,n)-1;
    rep1(_,stoppoint){
        vi af;
        int tmptmp = _;
        rep(i,n){
            af.push_back(tmptmp%2);
            tmptmp/=2;
        }
        int cnttmp = 0;
        for (int i = 0;i < n ;i+=2){
            cnttmp+=af[i];
            if(i+1<n)cnttmp-=af[i+1];
        }
        if(cnttmp!=0) continue;
        //prints("af");
        //for(auto x : af) cout << x << " "; prints();
        
        vector<pii> forsorta;
        vector<pii> forsortb;
        rep(i,n) {
            if(i%2 == 0){
                if(af[i] == 1){forsortb.push_back(mp(b[i+1],i+1));}
                else{forsorta.push_back(mp(a[i+1],i+1));}
            }
            else{
                if(af[i] == 0){forsortb.push_back(mp(a[i+1],i+1));}
                else{forsorta.push_back(mp(b[i+1],i+1));}
            }
        }
        sort(forsorta.begin(), forsorta.end());
        sort(forsortb.begin(), forsortb.end());



        pii bstmp[n];
        bool flag = false;
        rep(i,n) {
            if(i%2 == 0){
                bstmp[i] = forsorta[i/2];
               // prints(bstmp[i].F,bstmp[i].S);
            }
            else{
                bstmp[i] = forsortb[i/2];
                //prints(bstmp[i].F,bstmp[i].S);

            }
        }
        int nown = 0;
        bool outflag = false;
        rep(i,n){
            if(nown>bstmp[i].F){
                outflag = true;
                break;
            }
            else{
                nown = bstmp[i].F;
            }
        }

        if(outflag) continue;
        // prints("check point");

        int bs[n];

        rep(i,n) bs[i] = bstmp[i].S;

        int changecnt = 0;
        rep(itr,n){
            rep(i,n-1){
                if(bs[i] > bs[i+1]){
                    int tt = bs[i];
                    bs[i] = bs[i+1];
                    bs[i+1] = tt;
                    changecnt++;
                }
            }
        }
        fans = min(fans,changecnt);



        
        
    }

/*

    vector<int> v(n);
    iota(v.begin(), v.end(), 1);
    int fans = inf;
    v[]
    //do {
        // for(auto x : v) cout << x << " "; cout << "\n";
        int cnt = 0;
        rep(i,n){
            // prints(v[i],i+1);
            if (v[i]%2!=(i+1)%2){
                
                if((i+1)%2 == 0) {cnt++;}
                else{cnt--;}
            }
        }
        if(cnt!=0) continue;
        // prints("check point");


        vi tmp;
        rep1(i,n){
            if(i%2!=v[i-1]%2){tmp.push_back(b[v[i-1]]);}
            else{tmp.push_back(a[v[i-1]]);}
        }
        // cout << "tmp is ";
                // for(auto x : tmp) cout << x << " "; cout << "\n";

        int nown = 0;
        bool outflag = false;
        rep(i,n){
            if(nown>tmp[i]){
                outflag = true;
                break;
            }
            else{
                nown = tmp[i];
            }
        }

        if(outflag) continue;
        // prints("check point");


        int bs[n];
        rep(i,n) bs[i] = v[i];

        int changecnt = 0;
        rep(itr,n){
            rep(i,n-1){
                if(bs[i] > bs[i+1]){
                    int tt = bs[i];
                    bs[i] = bs[i+1];
                    bs[i+1] = tt;
                    changecnt++;
                }
            }
        }
        fans = min(fans,changecnt);

*/

    //} while( next_permutation(v.begin(), v.end()) );     // 次の順列を生成
    if(fans == inf){prints(-1);}
    else{prints(fans);}


    return 0;
}

Measured memory_bytes: 384