#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <cmath>
#include <queue>
#include <map>
#include <unordered_map>
#include <set>
#include <functional>
#include <bitset>
#include <numeric>
#include <complex>
#include <iomanip>
#include <cassert>
#include <random>


//#line 1 "lib/segment_tree.hpp"



#include <vector>
#include <algorithm>
#include <functional>

template<typename Monoid>
class SegmentTree {
public:
    using Operator = std::function<Monoid(Monoid, Monoid)>;

    SegmentTree(int n, const Operator &op, const Monoid init)
        : op(op), init(init) {

        num = 1;
        while (num < n) num *= 2;
        dat.resize(2 * num, init);
    }

    SegmentTree(const std::vector<Monoid> &m,
        const Operator &op, const Monoid init)
        : SegmentTree(m.size(), op, init) {

        int n = m.size();
        for (int i = 0; i < n; i++) {
            dat[num - 1 + i] = m[i];
        }
        for (int i = num - 2; i >= 0; i--) {
            dat[i] = op(dat[2 * i + 1], dat[2 * i + 2]);
        }
    }

    // Update the k-th value (0-indexed) to a.
    void update(int k, Monoid a) {
        k += num - 1;
        dat[k] = a;
        while (k > 0) {
            k = (k - 1) / 2;
            dat[k] = op(dat[2 * k + 1], dat[2 * k + 2]);
        }
    }

    // Get the value of the range [a, b).
    // k: The index of the node.
    // [left, right): The range corresponds to the k-th node.
    // Call like getval(a, b).
    Monoid getval(int a, int b, int k = 0, int left = 0, int right = -1) {
        if (right < 0) right = num;
        if (right <= a || b <= left) return init;
        if (a <= left && right <= b) return dat[k];
        Monoid vleft = getval(
            a, b, 2 * k + 1, left, left + (right - left) / 2);
        Monoid vright = getval(
            a, b, 2 * k + 2, left + (right - left) / 2, right);
        return op(vleft, vright);
    }

private:
    int num;
    std::vector<Monoid> dat;
    const Operator op;
    const Monoid init;
};


int main() {
    int n; std::cin >> n;
    std::vector<int> a(n), b(n);
    for (int i = 0; i < n; i++) std::cin >> a[i];
    for (int i = 0; i < n; i++) std::cin >> b[i];
    std::vector<int> c;
    std::vector<std::pair<int, int>> odd, even;
    int ans = 1e9;
    for (int s = 0; s < (1 << n); s++) {
        c.clear(); odd.clear(); even.clear();
        for (int i = 0; i < n; i++) {
            int z = (s >> i) & 1 ? b[i] : a[i];
            ((i & 1) ^ ((s >> i) & 1) ? odd : even).emplace_back(z, i);
        }
        if (even.size() != (n + 1) / 2) continue;
        if (odd.size() != n / 2) continue;
        std::sort(even.begin(), even.end());
        std::sort(odd.begin(), odd.end());
        for (int i = 0; i < n; i++) {
            c.push_back((i & 1 ? odd : even)[i / 2].first);
        }
        if (std::is_sorted(c.begin(), c.end())) {
            int cnt = 0;
            SegmentTree<int> seg(n, [](int a, int b) { return a + b; }, 0);
            for (int i = n - 1; i >= 0; i--) {
                int j = (i & 1 ? odd : even)[i / 2].second;
                cnt += seg.getval(0, j);
                seg.update(j, 1);
            }
            ans = std::min(ans, cnt);
        }
    }
    std::cout << (ans != 1e9 ? ans : -1) << std::endl;
    return 0;
}

Measured memory_bytes: 256