#include <iostream>
#include <cmath>
#include <cstring>

using namespace std;

typedef long long ll;
typedef pair <int, int> pii;
#define x first
#define y second
#define mp make_pair

const int MAXN = 18;
int n, a[MAXN + 5][2];
int dp[(1 << MAXN) + 5][55];
const int inf = (int)1e9;

int rek(int mask, int prev){
	if(!mask)
		return 0;
	int &ret = dp[mask][prev];
	if(ret != -1)
		return ret;
	ret = inf;
	for(int i = 0 ; i < n ; ++i){
		if(!(mask & (1 << i)))
			continue;
		int cur = n - __builtin_popcount(mask);
		int br = cur - (i - __builtin_popcount(mask & ((1 << i) - 1)));
		//cout << mask << ' ' << cur << ' ' << br << ' ' << i << endl;
		cur = abs(cur - i);
		int sad = a[i][(cur & 1)];
		if(sad >= prev){
			ret = min(ret, rek(mask ^ (1 << i), sad) + br);
		}
	}
	return ret;
}

int main(){
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
cin >> n;
for(int i = 0 ; i < n ; ++i){
	cin >> a[i][0];
}
for(int i = 0 ; i < n ; ++i){
	cin >> a[i][1];
}
memset(dp, -1, sizeof(dp));
int sol = rek((1 << n) - 1, 0);
if(sol == inf){
	cout << -1 << endl;
}
else{
	cout << sol << endl;
}

return 0;
}

