#include <bits/stdc++.h>

using namespace std;
typedef long long ll;

int N;
const int MAXN = 20;
const int big = MAXN*MAXN + 1;
int A[MAXN][2];
int dp[(1 << MAXN)][51][2];

int solve(int mask, int last, bool odd) {
	if (mask == 0) {
		return 0;
	}
	if (dp[mask][last][odd] >= 0) {
		return dp[mask][last][odd]; 
	}
	int best = big;	
	int count = 0;
	for (int i = 0; i < N; i++) {
		if (mask & (1 << i)) {
			int t = ((odd + i) % 2 ? A[i][1] : A[i][0]);
			if (t >= last) {
				int val = count + solve(mask ^ (1 << i), t, !odd);
				best = min(val, best);
			}
			count++;
		}
	}
	dp[mask][last][odd] = best;
	return best;
}

int main() {
	ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);	
	cin >> N;
	for (int i=0; i < N; i++) {
		cin >> A[i][0];
	}
	int mask = (1 << N) - 1;
	for (int i=0; i < N; i++) {
		cin >> A[i][1];
	}
	memset(dp, -1, sizeof dp);
	int swaps = solve(mask, 0, 0);
	if (swaps >= big) {
		cout << -1 << "\n";
	} else {
		cout << swaps << "\n";
	}
}

