#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
//#define P pair<ll,ll>
#define FOR(I,A,B) for(ll I = ll(A); I < ll(B); ++I)
#define FORR(I,A,B) for(ll I = ll((B)-1); I >= ll(A); --I)
#define TO(x,t,f) ((x)?(t):(f))
#define SORT(x) (sort(x.begin(),x.end())) // 0 2 2 3 4 5 8 9
#define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin()) //xi>=v  x is sorted
#define POSU(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin()) //xi>v  x is sorted
#define NUM(x,v) (POSU(x,v)-POSL(x,v))  //x is sorted
#define REV(x) (reverse(x.begin(),x.end())) //reverse
ll gcd(ll a,ll b){if(a%b==0)return b;return gcd(b,a%b);}
ll lcm(ll a,ll b){ll c=gcd(a,b);return ((a/c)*(b/c)*c);}
#define NEXTP(x) next_permutation(x.begin(),x.end())
const ll INF=ll(1e16)+ll(7);
const ll MOD=1000000007LL;
#define out(a) cout<<fixed<<setprecision((a))

struct Inversions{// tentosu
	// after init,u can get number of inversions num_inversion(A)
	vector<ll> L,R;
	void initsize(ll n){//input size of A
		L.resize(n/2+2);
		R.resize(n/2+2);
	}
	ll merge(vector<ll> &A,ll n,ll left,ll mid,ll right){
		ll i,j,k;
		ll cnt = 0;
		ll n1 = mid - left;
		ll n2 = right - mid;
		for(i=0;i<n1;i++)L[i]=A[left+i];
		for(i=0;i<n2;i++)R[i]=A[mid+i];
		L[n1]=R[n2]=INT_MAX;//
		i=j=0;
		for(k=left;k<right;k++){
			if(L[i]<=R[j]){
				A[k]=L[i++];
			}else{
				A[k]=R[j++];
				cnt += n1-i;
			}
		}
		return cnt;
	}
	ll mergeSort(vector<ll> &A,ll n,ll left,ll right){
		ll mid;
		ll v1,v2,v3;
		if(left+1<right){
			mid = (left+right)/2;
			v1 = mergeSort(A,n,left,mid);
			v2 = mergeSort(A,n,mid,right);
			v3 = merge(A,n,left,mid,right);
			return v1+v2+v3;
		}else return 0;
	}
	ll num_inversion(vector<ll> A){
		vector<ll> B=A;//Aの順番を変えたくないなら
		return mergeSort(B,B.size(),0,B.size());
	}
};

int main(){
	ll N;
	cin >> N;
	if(N==1){
		cout << 0 << endl;
		return 0;
	}
	vector<int> A(N),B(N);
	FOR(i,0,N) cin >> A[i];
	FOR(i,0,N) cin >> B[i];
	//　もともとiにいたカードは位置jmod2 == imod2 のjで赤

	int ans = -1;
	FOR(s,0,(1<<N)){
		vector<int> zero,one;
		vector<pair<int,int>> onex,zerox;
		int invcount = 0;
		FOR(i,0,N)if(s&(1<<i))invcount++;
		if(invcount%2) continue;
		FOR(i,0,N){
			if(s&(1<<i)){//裏返す
				if(i&1){
					zero.push_back(i);
					zerox.push_back({B[i],i});
				}else{
					one.push_back(i);
					onex.push_back({B[i],i});
				}
			}else{//裏返さない
				if(i&1){
					one.push_back(i);
					onex.push_back({A[i],i});
				}else{
					zero.push_back(i);
					zerox.push_back({A[i],i});
				}
			}
		}
		int zl = zerox.size();
		int ol = onex.size();
		if( zl!=ol && zl!=(ol+1) ){
			continue;
		}
		SORT(onex);SORT(zerox);
		bool none = false;
		FOR(i,0,ol){
			if(zerox[i].first>onex[i].first) none = true;
		}
		if(zl>ol)if(onex[ol-1].first > zerox[ol].first) none = true;
		if(none) continue;
		
		vector<ll> to_this_ind,xxx;
		FOR(i,0,ol){
			xxx.push_back(zerox[i].first);
			xxx.push_back(onex[i].first);
			to_this_ind.push_back(zerox[i].second);
			to_this_ind.push_back(onex[i].second);
		}
		if(zl>ol)to_this_ind.push_back(zerox[ol].second),xxx.push_back(zerox[ol].first);
		FOR(i,0,N-1){
			if(xxx[i]>xxx[i+1])none = true;
		}
		if(none)continue;
		int cnt = 0;
		Inversions inv;
		inv.initsize(N);
		cnt = inv.num_inversion(to_this_ind);
		if(ans==-1) ans = cnt;
		ans = min(ans,cnt);
	}

	cout << ans << endl;
}


Measured memory_bytes: 256