#include <bits/stdc++.h>
#define rep(i,n) for(int i=(0);i<(n);i++)

using namespace std;

typedef long long ll;
typedef pair<int, int> pii;

int main()
{
	cin.tie(0);
	ios::sync_with_stdio(false);

	int n;
	cin >> n;

	int a[n], b[n];
	rep(i, n) cin >> a[i];
	rep(i, n) cin >> b[i];

	int max_bit = (1 << n) - 1;
	int max_a = 52;
	int dp[max_bit + 1][max_a + 1];

	int INF = 1010101;
	rep(i, max_bit + 1) rep(j, max_a+1) dp[i][j] = INF;
	dp[0][0] = 0;

	rep(bit, max_bit + 1){
		int cnt = __builtin_popcount(bit);

		int t = cnt;
		vector<pii> v;

		rep(i, n){
			if(!((bit >> i) & 1)){
				v.push_back({i, t++});
			}
		}
		
		rep(j, max_a + 1){
			if(dp[bit][j] == INF) continue;

			for(pii p : v){
				int ns;
				if(abs(p.first - cnt) % 2 == 0){
					ns = a[p.first];
				}else{
					ns = b[p.first];
				}

				if(ns >= j){
					dp[bit | (1 << p.first)][ns] 
				     = min(dp[bit | (1 << p.first)][ns], dp[bit][j] + (p.second - cnt));
				}
				
			}
			
		}
	}

	int ans = INF;
	rep(i, max_a+1) ans = min(ans, dp[max_bit][i]);
	if(ans == INF) ans = -1;

	cout << ans << endl;
}
