#include<bits/stdc++.h>
using namespace std;
#define rep(i,x,y) for(int i=x;i<y;i++)
#define range(a) (a).begin(),(a).end()
#define print(A,n) rep(i,0,n){cout<<(i ? " ":"")<<A[i];}cout<<endl;
#define pprint(A,m,n) rep(j,0,m){print(A[j],n);}
const long mod=1e9+7;
const int size=1e5;
const int inf=1e9;
int main(){
	int N;cin>>N;
	int A[N],B[N];
    pair<int,int> C[N],D[N];
	rep(i,0,N) cin>>A[i];
    rep(i,0,N) cin>>B[i];
	int ans=inf;
	rep(i,0,(1<<N)){
		deque<pair<int,int>> even,odd;
		rep(j,0,N){
			if(i&(1<<j)){
                if(j%2==0) even.push_back({A[j],j});
                else even.push_back({B[j],j});
            }else{
                if(j%2) odd.push_back({A[j],j});
                else odd.push_back({B[j],j});
            }
		}
		if(odd.size()!=N/2) continue;
		sort(even.begin(),even.end());
		sort(odd.begin(),odd.end());
  		pair<int,int> vp[N];
		rep(j,0,N){
			if(j%2==0) vp[j]=even[j/2];
            else vp[j]=odd[j/2];
		}
        bool flag=false;
        rep(j,0,N-1){
			if(vp[j].first > vp[j+1].first) flag=true;
		}
        if(flag) continue;
		int cnt=0;
		rep(j,0,N)rep(k,0,j){
			if(vp[j].second < vp[k].second) cnt++;
		}
		ans=min(ans,cnt);
	}
	if(ans==inf) cout<<-1<<endl;
	else cout<<ans<<endl;
}