#pragma GCC optimize ("-O3")
#include <bits/stdc++.h>  
 
using namespace std;
 
typedef long long ll;
typedef long double ld;
typedef pair<int,int> p32;
typedef pair<ll,ll> p64;
typedef pair<double,double> pdd;
typedef vector<ll> v64;
typedef vector<int> v32;
typedef vector<vector<int> > vv32;
typedef vector<vector<ll> > vv64;
typedef vector<vector<p64> > vvp64;
typedef vector<p64> vp64;
typedef vector<p32> vp32;
ll MOD = 998244353;
#define forn(i,e) for(ll i = 0; i < e; i++)
#define forsn(i,s,e) for(int i = s; i < e; i++)
#define rforn(i,s) for(ll i = s; i >= 0; i--)
#define rforsn(i,s,e) for(ll i = s; i >= e; i--)
#define ln "\n"
#define dbg(x) cout<<#x<<" = "<<x<<ln
#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define INF 1e18
#define fast_cin() ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)
#define all(x) (x).begin(), (x).end()
#define sz(x) ((ll)(x).size())

ll mpow(ll a, ll b){
	if(b >= (MOD-1)) b %= (MOD-1);
	if(b==0) return 1;
	ll t1 = mpow(a,b/2);
	t1 *= t1;
	t1 %= MOD;
	if(b%2) t1 *= a;
	t1 %= MOD;
	return t1;
}

ll mpow(ll a, ll b, ll p){
	if(b==0) return 1;
	ll t1 = mpow(a,b/2,p);   t1 *= t1;
	t1 %= p;
	if(b%2) t1 *= a;
	t1 %= p;
	return t1;
}
ll modinverse(ll a, ll m){
	ll m0 = m; 
    ll y = 0, x = 1; 
    if (m == 1) return 0; 
    while (a > 1){
        ll q = a / m; 
        ll t = m; 
        m = a % m, a = t; 
        t = y; 
        y = x - q * y; 
        x = t; 
    }
    if (x < 0) x += m0; 
    return x; 
}
ll range(ll l, ll r){
	return l + rand()%(r-l+1);
}
     
void solve(){
    ll n;
    cin>>n;
    v64 a(n),b(n);
    forn(i,n)
    {
        cin>>a[i];
    }
    forn(i,n)
    {
        cin>>b[i];
        if(i%2)
        {
            swap(a[i], b[i]);
        }
    }
    ll ans = -1;
    vp64 st;
    forn(k, (1<<n))
    {
        vp64 tp(n);
        v64 tp1(n);
        forn(i, n)
        {
            if(((1 << i) & k))
            {
                tp[i] = mp(b[i], i);
            }
            else
            {
                tp[i] = mp(a[i], i);
            }
        }
        sort(all(tp));
            bool flg = 1;
            ll tmp = 0;
        forn(i, n)
        {
            ll j = i;
            while(j < n && tp[i].fi == tp[j].fi)
            {
                j++;
            }
            v64 od, ev, od1, ev1;
            forsn(k1, i, j)
            {
                if(((1 << (tp[k1].se)) & k))
                {
                    od.pb(tp[k1].se);
                }
                else
                {
                    ev.pb(tp[k1].se);
                }
                if(k1%2)
                {
                    od1.pb(k1);
                }
                else
                {
                    ev1.pb(k1);
                }
            }
            if(od1.size() == od.size())
            {
                forn(k1, od.size())
                {
                    tp1[od[k1]] = od1[k1];
                }
                forn(k1, ev.size())
                {
                    tp1[ev[k1]] = ev1[k1];
                }
            }
            else
            {
                flg = 0;
            }
            i = j-1;
        }
        if(flg)
        {
            forn(i, n)
            {
                forsn(j, i+1, n)
                {
                    if(tp1[i] > tp1[j])
                    {
                        tmp++;
                    }
                }
            }
            if(ans != -1)
            {
                ans = min(ans, tmp);
            }
            else
            {
                ans = tmp;
            }
        }
    }
    cout<<ans<<ln;
    // if(ans != 1e10)
    // {
    //     cout<<ans<<ln;
    //     forn(i, n)
    //     {
    //         cout<<st[i].fi<<" ";
    //     }
    //     cout<<ln;
    // }
    // else
    // {
    //     cout<<-1<<ln;
    // }
}
 
int main()
{
	fast_cin();
    ll t=1;
    //cin>>t;
    forn(i,t) {
    	// cout << "Case #" << i+1 << ": ";
    	solve();
    }
    return 0;
}

Measured memory_bytes: 384