#include<bits/stdc++.h>
using namespace std;

class InversionCount {
public:
    explicit InversionCount(vector<int64_t> target) : target_(std::move(target)) {}
    int64_t count(int64_t left = 0, int64_t right = -1) {
        if (right < 0) {
            //rはtarget_.size()で初期化
            right = target_.size();
        }
        if (right <= left + 1) {
            return 0;
        }
        int64_t mid = (left + right) / 2;
        int64_t result = 0;
        //左半分を数える
        result += count(left, mid);

        //右半分を数える
        result += count(mid, right);

        //左右またぐ数を数える
        result += merge(left, mid, right);

        return result;
    }

    const vector<int64_t>& v() { return target_; }
private:
    int64_t merge(int64_t left, int64_t mid, int64_t right) {
        vector<int64_t> l, r;
        for (int64_t i = left; i < mid; i++) {
            l.push_back(target_[i]);
        }
        for (int64_t i = mid; i < right; i++) {
            r.push_back(target_[i]);
        }
        //番兵
        l.push_back(LLONG_MAX);
        r.push_back(LLONG_MAX);

        int64_t left_index = 0;
        int64_t right_index = 0;
        int64_t result = 0;
        for (int64_t i = left; i < right; i++) {
            if (l[left_index] <= r[right_index]) {
                target_[i] = l[left_index];
                left_index++;
            } else {
                target_[i] = r[right_index];
                right_index++;
                result += ((mid - left) - left_index);
            }
        }
        return result;
    }

    vector<int64_t> target_;
};

int main() {
    int64_t N;
    cin >> N;
    vector<int64_t> A(N), B(N);
    for (int64_t& a : A) {
        cin >> a;
    }
    for (int64_t& b : B) {
        cin >> b;
    }

    const int64_t MAX_BIT = (1ull << N);
    int64_t ans = LLONG_MAX;
    for (int64_t i = 0; i < MAX_BIT; i++) {
        //iでビットが立っているところは最終的に裏で使う
        //[0, N)における偶数部分
        //もとから偶数で0またはもとは奇数で1
        //奇数部分は逆
        vector<pair<int64_t, int64_t>> even, odd;
        int64_t even_index = 0, odd_index = 1;
        for (int64_t j = 0; j < N; j++) {
            if (i & (1ull << j)) {
                if (j % 2 == 0) {
                    odd.emplace_back(B[j], j);
                    odd_index += 2;
                } else {
                    even.emplace_back(B[j], j);
                    even_index += 2;
                }
            } else {
                if (j % 2 == 0) {
                    even.emplace_back(A[j], j);
                    even_index += 2;
                } else {
                    odd.emplace_back(A[j], j);
                    odd_index += 2;
                }
            }
        }

        if (even.size() != (odd.size() + N % 2)) {
            continue;
        }

        sort(even.begin(), even.end());
        sort(odd.begin(), odd.end());

        //合法性判定
        bool ok = true;
        for (int64_t j = 0; j < N - 1; j++) {
            int64_t curr_value = (j % 2 == 0 ? even[j / 2].first : odd[j / 2].first);
            int64_t next_value = (j % 2 == 0 ? odd[(j + 1) / 2].first : even[(j + 1) / 2].first);
            if (curr_value > next_value) {
                ok = false;
                break;
            }
        }
        if (!ok) {
            continue;
        }

        vector<int64_t> from(N);
        for (int64_t j = 0; j < N; j++) {
            from[j] = (j % 2 == 0 ? even[j / 2].second : odd[j / 2].second);
        }

        InversionCount ic_first(from);
        int64_t curr_and = ic_first.count();

        ans = min(ans, curr_and);
    }

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

Measured memory_bytes: 256