#include <bits/stdc++.h>

using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
using WGraph = vector<vector<pair<int, ll>>>;

template<class T>inline bool chmax(T &a, const T &b) { if (b > a) { a = b; return true; } return false; }
template<class T>inline bool chmin(T &a, const T &b) { if (b < a) { a = b; return true; } return false; }

constexpr int dx[4] = {-1, 0, 0, 1}, dy[4] = {0, -1, 1, 0};
constexpr int INF = 1e9;
constexpr int MOD = 1e9 + 7;
constexpr long long LINF = 1e18;
constexpr double EPS = 1e-10;
constexpr double PI = M_PI;

template<class T>
class BinaryIndexedTree {
    private:
        int N;
        std::vector<T> dat;
    public:
        BinaryIndexedTree(int n) : N(n), dat(n+1, static_cast<T>(0)) {}
        // a is 1-indexed
        void add(int a, const T v) {
            while (a <= N) {
                dat[a] += v;
                a += (a & -a);
            }
        }
        // return sum of [1, a]
        // a is 1-indexed
        T sum(int a) const {
            T res = static_cast<T>(0);
            while (a > 0) {
                res += dat[a];
                a -= (a & -a);
            }
            return res;
        }
        // return sum of [a. b)
        // a and b are 1-indexed
        T sum(int a, int b) const {
            return sum(b-1) - sum(a-1);
        }
};

void solve() {
    int N;
    cin >> N;
    vector<int> a(N), b(N);
    for (int i=0; i<N; ++i) cin >> a[i];
    for (int i=0; i<N; ++i) cin >> b[i];

    int res = INF;
    for (int bits=0; bits<(1<<N); ++bits) {
        if (__builtin_popcount(bits)%2 != 0) continue;
        BinaryIndexedTree<int> pre(50), suf(50);
        for (int i=0; i<N; ++i) {
            int cur = (bits & (1<<i)) ? b[i] : a[i];
            suf.add(cur, 1);
        }
        int cnt = 0;
        vector<vector<bool>> eq(51);
        for (int i=0; i<N; ++i) {
            int cur = (bits & (1<<i)) ? b[i] : a[i];
            cnt += pre.sum(cur+1, 51);
            int tmp = pre.sum(cur+1, 51) + suf.sum(1, cur);
            if ((bool)(bits & (1<<i)) ^ (tmp%2 == 1)) eq[cur].push_back(false);
            else eq[cur].push_back(true);
            pre.add(cur, 1);
            suf.add(cur, -1);
        }
        for (int i=1; i<51; ++i) {
            if (eq[i].empty()) continue;
            int len = (int)eq[i].size();
            for (int j=0; j<len-1; ++j) {
                if (!eq[i][j]) {
                    if (!eq[i][j+1]) {
                        eq[i][j+1] = true;
                        ++cnt;
                    } else {
                        if (j < len-2 && eq[i][j+2]) {
                            cnt += 2;
                            eq[i][j+2] = false;
                        } else {
                            cnt = INF;
                            break;
                        }
                    }
                }
            }
            if (!eq[i].back()) cnt = INF;
            if (cnt == INF) break;
        }
        chmin(res, cnt);
    }
    cout << (res == INF ? -1 : res) << '\n';
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << fixed << setprecision(20);

    solve();

    return 0;
}


Measured memory_bytes: 256