#include <iostream>
#include <vector>
#include <algorithm>
#include <iomanip>
#include <string>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <tuple>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cassert>
#include <cstdint>
#include <cctype>
#include <numeric>
#include <bitset>
#include <functional>

using namespace std;

using ll =  long long;
using Pll = pair<ll, ll>;
using Pii = pair<int, int>;

constexpr int INF = 1 << 30;
constexpr ll LINF = 1LL << 60;
constexpr ll MOD = 1000000007;
constexpr long double EPS = 1e-10;
constexpr int dyx[4][2] = {
    { 0, 1}, {-1, 0}, {0,-1}, {1, 0}
};

int count_bit(unsigned  int n) {
    n = (n &  0x55555555) + (n >>  1  &  0x55555555);
    n = (n &  0x33333333) + (n >>  2  &  0x33333333);
    n = (n &  0x0f0f0f0f) + (n >>  4  &  0x0f0f0f0f);
    n = (n &  0x00ff00ff) + (n >>  8  &  0x00ff00ff);
    return (n &  0x0000ffff) + (n >>  16  &  0x0000ffff);
}

template<typename T>class BIT {
    public:
    int n;
    vector<T> bit;
    
    BIT(int n): n(n){
        bit.resize(n);
        fill(bit.begin(), bit.end(), (T)0);
    }

    void add(int idx, T x){
        for(int i=idx;i<=this->n;i+=i&-i) bit[i] += x;
    }

    //bit[1]からbit[end]までの和 (閉区間)
    T sum(int end){
        T ret = (T)0;
        for(int i=end;i>=1;i-=i&-i) ret += bit[i];
        return ret;
    }

    T count_swap(vector<int> &v){
        T ret = (T)0;
        int m = v.size();
        for(int i=1;i<=m;++i){
            add(v[i-1], 1);
            ret += i - sum(v[i-1]);
        }
        return ret;
    }
};


int main() {
    ios::sync_with_stdio(false); cin.tie(nullptr);
    int n;
    cin >> n;
    vector<Pii> a(n);
    for(int i=0;i<n;++i) {
        cin >> a[i].first;
    }
    for(int i=0;i<n;++i) {
        cin >> a[i].second;
    }

    int ans = INF;
    for(int bi=0;bi<(1<<n);++bi) {
        if(count_bit(bi) % 2) continue; // 裏返っているカードの数が奇数にはならない
        // cerr << bitset<10>(bi) << endl;

        vector<Pii> v[2];
        {
            vector<Pii> tmp_v(n);
            for(int i=0;i<n;++i) {
                if(bi & (1 << i)) {
                    tmp_v[i] = Pii(a[i].second, i);
                } else {
                    tmp_v[i] = Pii(a[i].first, i);
                }
            }
            sort(tmp_v.begin(), tmp_v.end());
            for(int i=0;i<n;++i) {
                v[((tmp_v[i].second%2)^((bi >> tmp_v[i].second) & 1))?1:0].emplace_back(tmp_v[i].first, tmp_v[i].second);
            }
        }

        bool is_ok = true;
        int prev_v = -1;
        vector<int> u(n);
        for(int i=0;i<n;++i) {
            if(i/2 >= v[i%2].size()) {
                is_ok = false;
                break;
            }
            if(prev_v > v[i%2][i/2].first) {
                is_ok = false;
                break;
            }
            // cerr << v[i%2][j[i%2]].first << " " << v[i%2][j[i%2]].second << endl;
            prev_v = v[i%2][i/2].first;
            u[i] = v[i%2][i/2].second + 1;
        }
        if(!is_ok) continue;

        // cerr << bitset<10>(bi) << ": " << "OK" << endl;

        BIT<int> tree(100);
        ans = min(ans, tree.count_swap(u));
    }

    cout << ((ans == INF)?-1:ans) << endl;
}


Measured memory_bytes: 256