#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <numeric>
#include <utility>
#include <tuple>

#define REP(i, a, b) for (int i = int(a); i < int(b); i++)
using namespace std;
using ll = long long int;
using P = pair<ll, ll>;

// clang-format off
#ifdef _DEBUG_
#define dump(...) do{ cerr << __LINE__ << ":\t" << #__VA_ARGS__ << " = "; PPPPP(__VA_ARGS__); cerr << endl; } while(false)
template<typename T> void PPPPP(T t) { cerr << t; }
template<typename T, typename... S> void PPPPP(T t, S... s) { cerr << t << ", "; PPPPP(s...); }
#else
#define dump(...) do{ } while(false)
#endif
template<typename T> vector<T> make_v(size_t a, T b) { return vector<T>(a, b); }
template<typename... Ts> auto make_v(size_t a, Ts... ts) { return vector<decltype(make_v(ts...))>(a, make_v(ts...)); }
template<typename T> bool chmin(T &a, T b) { if (a > b) {a = b; return true; } return false; }
template<typename T> bool chmax(T &a, T b) { if (a < b) {a = b; return true; } return false; }
template<typename T> void print(T a) { cout << a << endl; }
template<typename T, typename... Ts> void print(T a, Ts... ts) { cout << a << ' '; print(ts...); }
template<typename T> istream &operator,(istream &in, T &t) { return in >> t; }
class Range {
    using T = long long;
    class Iterator {
        T val, step, diff;
    public:
        Iterator(T v, T s, T d): val(v), step(s), diff(d) {}
        T operator*() { return val + diff; }
        bool operator!=(const Iterator &itr) { return step > 0 ? val < itr.val : val > itr.val; }
        Iterator operator++() { val += step; return *this; }
    };
    Iterator _begin, _end;
public:
    Range(T b, T e, T s, T d): _begin(b, s, d), _end(e, s, d) {
        if (s < 0) { _begin = Iterator(e - 1, s, d); _end = Iterator(b - 1, s, d); }
    }
    Range(T b, T e, T s): Range(b, e, s, 0) {}
    Range(T b, T e): Range(b, e, 1, 0) {}
    Range(T e): Range(0, e, 1, 0) {}
    Iterator begin() { return _begin; }
    Iterator end() { return _end; }
};
// clang-format on

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int n;
    cin, n;
    vector<int> a(n), b(n);
    for (ll i : Range(n)) {
        cin, a[i];
    }
    for (ll i : Range(n)) {
        cin, b[i];
    }

    int sz = 1 << n;
    const int inf = 1 << 30;
    int ans = inf;
    for (ll i : Range(sz)) {
        vector<P> cs[2];
        vector<P> ar(n);
        for (ll j : Range(n)) {
            int bit = ((j & 1) + (i >> j) & 1) % 2;
            int ab = (i >> j) & 1;
            if (ab) {
                cs[bit].emplace_back(b[j], j);
                ar[j] = {b[j], 0};
            } else {
                cs[bit].emplace_back(a[j], j);
                ar[j] = {a[j], 0};
            }
        }
        if (cs[0].size() != (n + 1) / 2 || cs[1].size() != n / 2) continue;

        {
            auto ce = cs[0], co = cs[1];
            sort(ce.begin(), ce.end());
            sort(co.begin(), co.end());
            ll prev = -1;
            bool ok = true;
            vector<int> cnt(100, 0);
            for (ll j : Range(n)) {
                ll index;
                if (j & 1) {
                    if (prev > co[j / 2].first) {
                        ok = false;
                    }
                    prev = co[j / 2].first;
                    index = co[j / 2].second;
                } else {
                    if (prev > ce[j / 2].first) {
                        ok = false;
                    }
                    prev = ce[j / 2].first;
                    index = ce[j / 2].second;
                }
                ar[index].second = cnt[prev];
                cnt[prev]++;
            }
            if (!ok) {
                continue;
            }
        }

        int cnt = 0;
        for (ll j : Range(n)) {
            for (ll k : Range(j)) {
                cnt += (ar[k] > ar[j]);
            }
        }

        chmin(ans, cnt);
        dump(i, cnt);
    }
    if (ans == inf) {
        ans = -1;
    }
    print(ans);

    return 0;
}


Measured memory_bytes: 256