#include<bits/stdc++.h>
#define ll long long
#define ull unsigned ll
#define uint unsigned
#define pii pair<int,int>
#define pll pair<ll,ll>
#define IT iterator
#define PB push_back
#define fi first
#define se second
#define For(i,j,k) for (int i=(int)(j);i<=(int)(k);i++)
#define Rep(i,j,k) for (int i=(int)(j);i>=(int)(k);i--)
#define CLR(a,v) memset(a,v,sizeof(a));
#define CPY(a,b) memcpy(a,b,sizeof(a));
#define debug puts("wzpakking")
#define y1 ysghysgsygsh
using namespace std;
const int N=20;
int n,a[N],b[N];
int f[1<<18][N],cnt[1<<18];
int main(){
	scanf("%d",&n);
	For(i,0,n-1) scanf("%d",&a[i]);
	For(i,0,n-1) scanf("%d",&b[i]);
 	memset(f,60,sizeof(f));
	For(i,0,n-1) f[1<<i][i]=0;
	For(i,0,(1<<n)-1) cnt[i]=cnt[i/2]+(i&1);
	For(i,1,(1<<n)-1) For(j,0,n-1){
		if (!(i&(1<<j))) continue;
		int v=(abs(j-cnt[i]-1)&1?b[j]:a[j]),dif=0;
		//cout<<i<<' '<<j<<' '<<v<<endl;
		Rep(k,n-1,0) if (!(i&(1<<k))){
			int vv=(abs(k-cnt[i])&1?b[k]:a[k]);
			if (vv<v) continue;
			//cout<<j<<' '<<k<<' '<<dif<<endl;
			f[i|(1<<k)][k]=min(f[i|(1<<k)][k],f[i][j]+dif);
		}
		else ++dif;
	}
	int ans=1<<30;
	For(i,0,n-1) ans=min(ans,f[(1<<n)-1][i]);
	printf("%d\n",ans>10000?-1:ans);
}