#include <algorithm>
#include <iostream>
#include <vector>
#include <math.h>
#include <set>
#include <map>
#include <string>
#include <stack>
#include <queue>
#include <iomanip>
#include <numeric>
#include <tuple>
#include <bitset>
#include <complex>
#include <unistd.h>
#include <cassert>
#include <cctype>
#include <random>
#include <time.h>
#define _USE_MATH_DEFINES
#define _GLIBCXX_DEBUG
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> plglg;
typedef pair<double, ll> pdlg;
typedef tuple<int, int, int> tiii;
typedef tuple<ll, ll, ll> tlglglg;
typedef tuple<double, double, double> tddd;
typedef complex<double> xy_t;
typedef vector<ll> vll;
typedef vector< vector<ll> > matrix;
#define REP(i, x, y) for(ll i = (ll)x; i < (ll)y; i++)
#define DREP(i, x, y, d) for(ll i = (ll)x; i < (ll)y; i += (ll)d)
#define PER(i, x, y) for(ll i = (ll)x; i > (ll)y; i--)
#define DPER(i, x, y, d) for(ll i = (ll)x; i > (ll)y; i -= (ll)d)
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
double pi = 3.141592653589793;
ll mod = 1000000007;
int intmax = 2147483647;
int intmin = -2147483648;
ll llmax = 9223372036854775807;
ll llmin = -9223372036854775807;
int iinf = intmax / 8;
ll inf = llmax / 8;
double eps = 1e-12;

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll N;
    cin >> N;
    ll A[N], B[N];
    REP(i, 0, N) {
        cin >> A[i];
    }
    REP(i, 0, N) {
        cin >> B[i];
    }
    if (N == 1) {
        cout << 0 << endl;
        return 0;
    }
    if (N == 2) {
        if (A[0] <= B[0]) {
            cout << 0 << endl;
        } else if (B[1] <= A[1]) {
            cout << 1 << endl;
        } else {
            cout << -1 << endl;
        }
        return 0;
    }
    ll ans = inf;
    REP(bit, 0, ((ll)1 << N)) {
        ll bitnuma = 0;
        ll bitnumb = 0;
        ll basebit = 0;
        vector<plglg> a, b;
        REP(i, 0, N) {
            if (bit & ((ll)1 << i)) {
                basebit++;
                if (i & 1) {
                    bitnuma++;
                    a.push_back(plglg(B[i], i));
                } else {
                    bitnumb++;
                    b.push_back(plglg(B[i], i));
                }
            } else {
                if (i & 1) {
                    bitnumb++;
                    b.push_back(plglg(A[i], i));
                } else {
                    bitnuma++;
                    a.push_back(plglg(A[i], i));
                }
            }
        }
        if (basebit % 2 == 1) {
            continue;
        }
        if (N % 2 == 1) {
            if (bitnuma - bitnumb != 1) {
                continue;
            }
        } else {
            if (bitnuma != bitnumb) {
                continue;
            }
        }
        sort(a.begin(), a.end());
        sort(b.begin(), b.end());
        vector<ll> vecbase;
        vector<ll> vec;
        REP(i, 0, b.size()) {
            vecbase.push_back(a[i].first);
            vecbase.push_back(b[i].first);
            vec.push_back(a[i].second);
            vec.push_back(b[i].second);
        }
        if (N % 2 == 1) {
            vec.push_back(a[bitnuma - 1].second);
            vecbase.push_back(a[bitnuma - 1].first);
        }
        bool ok = true;
        REP(i, 0, N - 1) {
            if (vecbase[i] > vecbase[i + 1]) {
                ok = false;
                break;
            }
        }
        if (!ok) {
            continue;
        }
        ll tmp = 0;
        REP(i, 0, N - 1) {
            REP(j, i + 1, N) {
                if (vec[i] > vec[j]) {
                    tmp++;
                }
            }
        }
        // cout << bit << " " << tmp << endl;
        ans = min(ans, tmp);
    }
    if (ans == inf) {
        cout << -1 << endl;
    } else {
        cout << ans << endl;
    }
}


Measured memory_bytes: 256