#include "bits/stdc++.h"
using namespace std;
using ll     = long long;
using pii    = pair<int, int>;
using pll    = pair<ll, ll>;
using vi     = vector<int>;
using vl     = vector<ll>;
using vvi    = vector<vi>;
using vvl    = vector<vl>;
const ll INF = 1LL << 60;
const ll MOD = 1000000007;
template <class T>
bool chmax(T &a, const T &b) {
    return (a < b) ? (a = b, 1) : 0;
}
template <class T>
bool chmin(T &a, const T &b) {
    return (b < a) ? (a = b, 1) : 0;
}
template <class C>
void print(const C &c, std::ostream &os = std::cout) {
    std::copy(std::begin(c), std::end(c), std::ostream_iterator<typename C::value_type>(os, " "));
    os << std::endl;
}

// Binary Indexed Tree / Fenwick tree
// can calculate partial sum in O(logN)
// can update single datum in O(logN)
// lower_bound is binary search O(logN)
// 0-indexed!!!
template <typename T = int>
struct BinaryIndexedTree {
    int n;
    vector<T> bit;
    BinaryIndexedTree(int n_, T init = 0) : n(n_), bit(n_ + 1, init) {}
    BinaryIndexedTree(vector<T> init) : n(init.size() + 1), bit(init.size() + 1) {
        for (int i = 1; i < init.size() + 1; ++i) {
            bit[i] = init[i - 1];
        }
    }
    T sum(int i) {
        i++;
        T s = bit[0];
        for (int x = i; x > 0; x -= (x & -x))
            s += bit[x];
        return s;
    }
    void add(int i, T a) {
        i++;
        if (i == 0)
            return;
        for (int x = i; x <= n; x += (x & -x))
            bit[x] += a;
    }
    int lower_bound(int w) {
        if (w <= 0)
            return 0;
        int x = 0, r = 1;
        while (r < n)
            r <<= 1;
        for (int k = r; k > 0; k >>= 1) {
            if (x + k <= n && bit[x + k] < w) {
                w -= bit[x + k];
                x += k;
            }
        }
        return x + 1;
    }
    int upper_bound(int w) {
        if (w < 0)
            return 0;
        int x = 0, r = 1;
        while (r < n)
            r <<= 1;
        for (int k = r; k > 0; k >>= 1) {
            if (x + k <= n && bit[x + k] <= w) {
                w -= bit[x + k];
                x += k;
            }
        }
        return x + 1;
    }
    T query(int l, int r) { return sum(r - 1) - sum(l - 1); }
};

int main() {
    ll n;
    cin >> n;
    vl a(n), b(n);
    for (int i = 0; i < n; ++i) {
        cin >> a[i];
    }
    for (int i = 0; i < n; ++i) {
        cin >> b[i];
    }
    vl even(n, 0);
    for (int i = 0; i < n; ++i) {
        even[i] = i % 2;
    }
    sort(even.begin(), even.end());
    ll result = INF;
    do {
        vector<pll> e;
        vector<pll> o;
        for (int i = 0; i < n; ++i) {
            if (even[i] == 0) {
                if (i % 2 == 0) {
                    o.emplace_back(a[i], i);
                } else {
                    o.emplace_back(b[i], i);
                }
            } else {
                if (i % 2 == 0) {
                    e.emplace_back(b[i], i);
                } else {
                    e.emplace_back(a[i], i);
                }
            }
        }
        sort(e.begin(), e.end());
        sort(o.begin(), o.end());
        vector<pll> ret;
        for (int i = 0; i < (int)e.size(); ++i) {
            ret.push_back(o[i]);
            ret.push_back(e[i]);
        }
        if (o.size() > e.size())
            ret.push_back(o.back());
        bool ok = true;
        for (int i = 1; i < (int)ret.size(); ++i) {
            if (ret[i].first < ret[i - 1].first) {
                ok = false;
                break;
            }
        }
        if (ok) {
            ll temp = 0;
            BinaryIndexedTree<int> bit(n);
            for (int i = 0; i < n; ++i) {
                temp += bit.query(ret[i].second, n);
                bit.add(ret[i].second, 1);
            }
            chmin(result, temp);
        }
    } while (next_permutation(even.begin(), even.end()));
    if (result == INF) {
        cout << -1 << "\n";
    } else {
        cout << result << "\n";
    }
    // for (int r = 0; r <= n; r += 2) {
    //     vl red(n, 0);
    //     for (int i = 0; i < r; ++i) {
    //         red[i] = 1;
    //     }
    //     reverse(red.begin(), red.end());
    //     do {
    //         vl c(n);
    //         for (int i = 0; i < n; ++i) {
    //             if (red[i])
    //                 c[i] = a[i];
    //             else
    //                 c[i] = b[i];
    //         }

    //     } while (next_permutation(red.begin(), red.end()));
    // }
    return 0;
}

Measured memory_bytes: 384