// May this submission get accepted
#pragma GCC optimize ("O3")

#include <bits/stdc++.h>

// 汎用マクロ
#define ALL_OF(x) (x).begin(), (x).end()
#define REP(i,n) for (long long i=0, i##_len=(n); i<i##_len; i++)
#define RANGE(i,is,ie) for (long long i=(is), i##_end=(ie); i<=i##_end; i++)
#define DSRNG(i,is,ie) for (long long i=(is), i##_end=(ie); i>=i##_end; i--)
#define STEP(i, is, ie, step) for (long long i=(is), i##_end=(ie), i##_step = (step); i<=i##_end; i+=i##_step)
#define UNIQUE(v) do { sort((v).begin(), (v).end()); (v).erase(unique((v).begin(), (v).end()), (v).end()); } while (false)
template<class T> bool chmax(T &a, const T &b) { if (a < b) {a = b; return true;} return false; }
template<class T> bool chmin(T &a, const T &b) { if (a > b) {a = b; return true;} return false; }
#define INF 0x7FFFFFFF
#define LINF 0x7FFFFFFFFFFFFFFFLL
#define Yes(q) ((q) ? "Yes" : "No")
#define YES(q) ((q) ? "YES" : "NO")
#define Possible(q) ((q) ? "Possible" : "Impossible")
#define POSSIBLE(q) ((q) ? "POSSIBLE" : "IMPOSSIBLE")
#define DUMP(q) cerr << "[DEBUG] " #q ": " << (q) << " at " __FILE__ ":" << __LINE__ << endl
#define DUMPALL(q) do { cerr << "[DEBUG] " #q ": ["; REP(DUMPALL_ITR, (q).size()) { cerr << (q)[DUMPALL_ITR] << (DUMPALL_ITR == DUMPALL_ITR_len-1 ? "" : ", "); } cerr << "] at " __FILE__ ":" << __LINE__ << endl; } while (false)
template<class T> T gcd(T a, T b) { if (a < b) std::swap(a, b); while (b) std::swap(a %= b, b); return a; }
template<class T> T lcm(const T a, const T b) { return a / gcd(a, b) * b; }

// gcc拡張マクロ
#define popcount __builtin_popcount
#define popcountll __builtin_popcountll

// エイリアス
#define DANCE_ long
#define ROBOT_ unsigned
#define HUMAN_ signed
using  ll = DANCE_ HUMAN_ DANCE_;
using ull = DANCE_ ROBOT_ DANCE_;
using  ld = long double;
using namespace std;

// 標準入出力
struct inp {
    size_t sz;
    inp(size_t _sz = 1) : sz(_sz) {}
    template <typename T> operator T () const { T a; cin >> a; return a; }
    template <typename T> operator vector<T> () const { vector<T> a(sz); for (size_t i = 0; i < sz; i++) cin >> a[i]; return a; }
    template <typename T, typename U> operator pair<T, U> () const { T f; U s; cin >> f >> s; return pair<T, U>(f, s); }
};
inp inp1; // input one
template <typename T> void say(T &x, char end = '\n') { cout << x << end; }
template <typename T> void say(vector<T> &x, char sep = ' ', char end = '\n') { for (size_t i = 0, sz = x.size(); i < sz; i++) { cout << x[i] << (i == sz-1 ? end : sep); } }

// モジュール

// 座圧 {写像, 逆写像} が返る O(NlogN)
template <typename T>
pair<map<T, int>, vector<T>> sahz(const vector<T> &x0) {
    vector<T> x = x0;
    sort(x.begin(), x.end());
    x.erase(unique(x.begin(), x.end()), x.end());
    map<T, int> r;
    for (int i = 0; i < x.size(); i++) {
        r[x[i]] = i;
    }
    return make_pair(r, x);
}

// Binary Indexed Tree モジュール (0-indexed)
template <typename T>
class BIT {
private:
    vector<T> val;
public:
    ull n;
    BIT(ull _n) : val(_n+1, 0), n(_n) {}
    BIT(vector<T> arr) : val(arr.size() + 1, 0), n(arr.size()) {
        REP(i, n) add(i, arr[i]);
    }
    // a[i] に v を足す O(logN)
    void add(const ull _i, const T _v) {
        for (ull i = _i + 1; i <= n; i += i & (-i)) {
            val[i] += _v;
        }
    }
    // [0, _i) の和を求める O(logN)
    T get(ull i) const {
        T ans = 0;
        for (; i > 0; i ^= i & (-i)) {
            ans += val[i];
        }
        return ans;
    }
    // [l, r) の和を求める o(N)
    T sum(const ull l, const ull r) {
        return get(r) - get(l);
    }
};

// BITを用いて数列の転倒数を求める。O(NlogN)。
// bit.cppを必要とする。
template <typename T>
size_t inversion(vector<T> &x0) {
    
    vector<T> x = x0;
    const int n = x0.size();
    
    // 座圧
    vector<T> unq = x;
    sort(unq.begin(), unq.end());
    unq.erase(unique(unq.begin(), unq.end()), unq.end());
    map<T, int> sahz;
    for (size_t i = 0; i < unq.size(); i++) sahz[unq[i]] = i;
    for (size_t i = 0; i < x.size(); i++) x[i] = sahz[x[i]];
    
    // BITで転倒数を求める
    size_t ans = 0;
    BIT<int> bit(n);
    for (int i = 0; i < n; i++) {
        ans += bit.sum(x[i]+1, n);
        bit.add(x[i], 1);
    }
    
    return ans;
    
}


// 処理内容
int main() {
    
    ios::sync_with_stdio(false); // stdioを使うときはコメントアウトすること
    cin.tie(nullptr);            // インタラクティブ問題ではコメントアウトすること
    
    ll n = inp1;
    vector<ll> a = inp(n), b = inp(n);

    // 座圧
    vector<ll> ab;
    copy(ALL_OF(a), back_inserter(ab));
    copy(ALL_OF(b), back_inserter(ab));
    auto r = sahz(ab);
    for (ll &x : a) x = r.first[x];
    for (ll &x : b) x = r.first[x];

    // DUMPALL(a);
    // DUMPALL(b);

    ll ans = INF;
    REP(i, 1<<n) {
        if (popcountll(i) % 2 == 1) continue;
        vector<pair<ll, ll>> c(n);
        REP(j, n) {
            c[j] = make_pair(i>>j&1, j); // {裏か, 元の位置}
        }
        sort(ALL_OF(c), [&](pair<ll,ll> &x, pair<ll,ll> &y) {
            ll xv = (x.first ? b : a)[x.second];
            ll yv = (y.first ? b : a)[y.second];
            return xv < yv;
        });
        bool okay = true;
        for (ll l = 0, r = 0; l < n;) {
            while (r < n && (c[l].first?b:a)[c[l].second] == (c[r].first?b:a)[c[r].second]) r++;

            vector<pair<ll, ll>> evens, odds;
            RANGE(j, l, r-1) {
                (c[j].first ^ (c[j].second % 2) ? odds : evens).push_back(c[j]);
            }

            sort(ALL_OF(evens), [&](pair<ll, ll> &x, pair<ll, ll> &y) { return x.second < y.second; });
            sort(ALL_OF( odds), [&](pair<ll, ll> &x, pair<ll, ll> &y) { return x.second < y.second; });

            ll ie = 0, io = 0;
            RANGE(j, l, r-1) {
                ll par = j % 2;
                ll &i = par ? io : ie;
                auto &s = par ? odds : evens;
                if (i >= s.size()) {
                    okay = false;
                    break;
                }
                c[j] = s[i++];
            }
            if (!okay) break;

            l = r;
        }
        if (!okay) continue;
        REP(j, n) {
            if (c[j].first ^ (abs(j - c[j].second) % 2)) {
                okay = false;
                break;
            }
        }
        if (!okay) continue;
        vector<ll> idx(n);
        REP(j, n) idx[j] = c[j].second;
        chmin(ans, (ll)inversion(idx));
    }
    if (ans == INF) ans = -1;
    say(ans);
    
}

Measured memory_bytes: 384