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

#define int long long
#define endl "\n"
#define REP(i,a,n) for(int i=a;i<n;++i)
#define REPR(i,a,n) for(int i=a;i>n;--i)
#define RUP(a,b) ((a+b-1)/(b))
#define ALL(v) (v).begin(),(v).end()
#define pb push_back
#define mp make_pair
#define mt make_tuple
//#define MOD 1000000007
#define INF LLONG_MAX/2

typedef long long ll;
typedef pair<int,int> Pii;
typedef tuple<int,int,int> Tiii;
typedef vector<int> Vi;
typedef vector<Vi> VVi;
typedef vector<Pii> VPii;
typedef vector<string> Vs;

template<class T> inline bool chmax(T& a,T b){if(a<b){a=b;return 1;}return 0;}
template<class T> inline bool chmin(T& a,T b){if(a>b){a=b;return 1;}return 0;}
template<class T> void YesNo(T a) {cout<<(a?"Yes":"No")<<endl;}
template<class T> void YESNO(T a) {cout<<(a?"YES":"NO")<<endl;}
void vin(Vi &v){REP(i,0,(v).size()) cin>>v[i];}
void vin(Vi &v,Vi &v2){REP(i,0,(v).size()) cin>>v[i]>>v2[i];}
void vout(Vi &v){for(int i=0;i<(v).size();i++) cout<<v[i]<<" ";cout<<endl;}
int gcd(int a,int b){return b?gcd(b,a%b):a;}
int lcm(int a,int b){return a/gcd(a,b)*b;}
void uniq(Vi &v){sort(v.begin(),v.end()); v.erase(unique(v.begin(),v.end()),v.end());}
int ctoi(char c){if(c>='0'&&c<='9'){return c-'0';}return 0;}
void accum(Vi &v){REP(i,1,(v).size()) v[i]+=v[i-1];}
bool comp(Pii a,Pii b){
    if(a.second != b.second) return a.second<b.second;
    else return a.first<b.first;
}

template <typename T> bool next_combination(const T first, const T last, int k) {
    const T subset = first + k;
    // empty container | k = 0 | k == n 
    if (first == last || first == subset || last == subset) {
        return false;
    }
    T src = subset;
    while (first != src) {
        src--;
        if (*src < *(last - 1)) {
            T dest = subset;
            while (*src >= *dest) {
                dest++;
            }
            iter_swap(src, dest);
            rotate(src + 1, dest + 1, last);
            rotate(subset, subset + (last - dest) - 1, last);
            return true;
        }
    }
    // restore
    rotate(first, subset, last);
    return false;
}

// void recursive_comb(int *indexes, int s, int rest, std::function<void(int *)> f) {
//   if (rest == 0) {
//     f(indexes);
//   } else {
//     if (s < 0) return;
//     recursive_comb(indexes, s - 1, rest, f);
//     indexes[rest - 1] = s;
//     recursive_comb(indexes, s - 1, rest - 1, f);
//   }
// }

// // nCkの組み合わせに対して処理を実行する
// void foreach_comb(int n, int k, std::function<void(int *)> f) {
//   int indexes[k];
//   recursive_comb(indexes, n - 1, k, f);
// }


void solve(long long n, std::vector<long long> a, std::vector<long long> b){
    // VPii odd(n),even(n);
    // REP(i,0,n){
    //     if(i%2==0){
    //         even[i].first=a[i];
    //         odd[i].first=b[i];
    //     }else{
    //         even[i].fisrt=b[i];
    //         odd[i].first=a[i];
    //     }
    // }
    VPii odd(n),even(n);
    Vi v(n);
    int k=RUP(n,2);
    REP(i,0,n){
        if(i%2==0){
            even[i].first=a[i];
            odd[i].first=b[i];
        }else{
            even[i].first=b[i];
            odd[i].first=a[i];
        }
        even[i].second=i;
        odd[i].second=i;
        v[i]=i;
    }

//   foreach_comb(5, 3, [](int *indexes) {
//     cout << indexes[0] << ',' << indexes[1] << ',' << indexes[2] << endl;
//   });
    // VVi test;
    // foreach_comb(n,RUP(n,2),[](int *indexes){
        // VPii e(RUP(n,2));
        // REP(i,0,e.size()){
        //     e[i].first=even[index[i]].first;
        //     e[i].second=even[index[i]].second;
        //     sort(ALL(e));
        // }
        // VPii o(n/2);
        // REP(i,0,n){
        //     bool check=false;
        //     REP(j,0,RUP(n,2)){
        //         if(i==indexes[j]) check=true;
        //     }
        //     if(check) continue;
        //     o[i].first=odd[index[i]].first;
        //     o[i].second=odd[index[i]].second;
        //     sort(ALL(o));
        // }

        // cout << indexes[0] << ',' << indexes[1] << ',' << indexes[2] << endl;
        // test.pb(indexes);
        // vout(e);
        // cout<<endl;
        // vout(o);
        // cout<<endl<<endl;

    // });
    VVi evens,odds;
    do{
        Vi tmp,tmp2;
        for (int i = 0; i < k; i++) {
//            cout << v[i] << " ";
            tmp.pb(v[i]);
        }
//        cout << "| ";
        for (int i = k; i < v.size(); i++) {
            // cout << v[i] << " ";
            tmp2.pb(v[i]);
        }
//        cout << endl;
        evens.pb(tmp);
        odds.pb(tmp2);
    }while(next_combination(v.begin(), v.end(), k));

    // REP(i,0,evens.size()){
    //     vout(evens[i]);
    //     vout(odds[i]);
    // }
    int ans=INF;
    REP(i,0,evens.size()){
        VPii e,o;
        REP(j,0,evens[i].size()) e.pb(even[evens[i][j]]);
        REP(j,0,odds[i].size()) o.pb(odd[odds[i][j]]);
//        REP(j,0,e.size()) cout<<e[j].first<<endl;
        sort(ALL(e));
        sort(ALL(o));
        VPii newv(n);
        REP(j,0,n){
            if(j%2==0) newv[j]=e[j/2];
            else newv[j]=o[j/2];
        }
        // REP(j,0,n) cout<<newv[j].first<<" ";
        // cout<<endl;
        bool check=false;
        REP(j,1,n){
            if(newv[j].first<newv[j-1].first) check=true;
        }
        if(check) continue;
        int tmpans=0;
        REP(j,0,n){
            REP(k,j+1,n){
                if(newv[j].second>newv[k].second) tmpans++;
            }
        }
        chmin(ans,tmpans);
    }
    if(ans!=INF) cout<<ans<<endl;
    else cout<<-1<<endl;
}

// Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
signed main(){
    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]);
    }
    solve(N, std::move(A), std::move(B));
    return 0;
}


Measured memory_bytes: 13288