/**
 *    author:  otera    
**/
#include<iostream>
#include<string>
#include<cstdio>
#include<cstring>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<deque>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<complex>
#include<bitset>
#include<stack>
#include<unordered_map>
#include<utility>
#include<cassert>
using namespace std;

typedef long long ll;
typedef unsigned long long ul;
typedef unsigned int ui;
typedef long double ld;
const int inf=1e9+7;
const ll INF=1LL<<60 ;
const ll mod=1e9+7 ;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
typedef complex<ld> Point;
const ld eps = 1e-8;
const ld pi = acos(-1.0);
typedef pair<int, int> P;
typedef pair<ld, ld> LDP;
typedef pair<ll, ll> LP;
#define fr first
#define sc second
#define all(c) c.begin(),c.end()
#define pb push_back
#define debug(x)  cerr << #x << " = " << (x) << endl;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
//#define int long long

template <class Abel> struct BIT {
private:
	vector<Abel> node; int n;
    Abel UNITY_SUM = 0; //to be set
public:
	BIT(int n_) {
		n = n_; node.resize(n, UNITY_SUM);
	}
	//0-indexed
	void add(int a, Abel w) {
		for (int i = a; i < n; i |= i + 1)node[i] += w;
	}
	//[0,a)
	Abel sum(int a) {
		Abel ret = UNITY_SUM;
		for (int i = a - 1; i >= 0; i = (i&(i + 1)) - 1)ret += node[i];
		return ret;
	}
	//[a,b)
	Abel sum(int a, int b) {
		return sum(b) - sum(a);
	}
	//k-th number (k is 0-indexed)
    int get(int k) {
        ++k;
        int res = 0;
        int n = 1; while(n < (int)node.size()) n *= 2;
        for(int i = n / 2; i > 0; i /= 2) {
            if(res + i < (int)node.size() && node[res + i - 1] < k) {
                k -= node[res + i - 1];
                res += i;
            }
        }
        return res; //0-indexed
    }
    //debug
    void print() {
        for(int i = 0; i < n; ++i) cout << sum(i, i + 1) << ",";
        cout << endl;
    }
};

void solve() {
	int n; cin >> n;
    vector<int> a(n), b(n);
    vector<P> c(n);
    rep(i, n) {
        cin >> a[i];
    }
    rep(i, n) {
        cin >> b[i];
        c[i] = make_pair(a[i], b[i]);
    }
    int ans = inf;
    for(int bit = 0; bit < (1<<n); ++bit) {
        int cnt = __builtin_popcount(bit);
        if(cnt & 1) continue;
        bool flag = 1;
        //vector<P> d(n);
        vector<P> odd, even;
        rep(i, n) {
            if(bit & (1<<i)) {
                //d[i] = make_pair(b[i], i);
                if(i & 1) {
                    even.pb(make_pair(b[i], i));
                } else {
                    odd.pb(make_pair(b[i], i));
                }
            }
            else {
                //d[i] = make_pair(a[i], i);
                if(i & 1) {
                    odd.pb(make_pair(a[i], i));
                } else {
                    even.pb(make_pair(a[i], i));
                }
            }
        }
        if(even.size() != (n + 1) / 2) continue;
        sort(all(even));
        sort(all(odd));
        vector<P> e(n);
        int odcnt = 0, evcnt = 0;
        rep(i, n) {
            if(i & 1) {
                e[i] = odd[odcnt];
                ++odcnt;
            } else {
                e[i] = even[evcnt];
                ++evcnt;
            }
            if(i > 0) {
                if(e[i - 1].fr > e[i].fr) {
                    flag = 0;
                    break;
                }
            }
        }
        if(!flag) continue;
        int co = 0;
        BIT<int> bi(n);
        rep(j, n) {
            co += j - bi.sum(e[j].sc);
            bi.add(e[j].sc, 1);
        }
        chmin(ans, co);
    }
    if(ans == inf) {
        cout << -1 << endl;
    } else {
        cout << ans << endl;
    }
}

signed main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	//cout << fixed << setprecision(10);
	//init();
	//int t; cin >> t; rep(i, t)solve();
	solve();
	//cout << "finish" << endl;
    return 0;
}

Measured memory_bytes: 256