#include <bits/stdc++.h>
#define pb push_back
#define pll pair <ll, ll>
#define mp make_pair
#define pyshnapyshnakaa ios_base :: sync_with_stdio(0); cin.tie(0); cout.tie(0);
#pragma optimize("TKACHENKO-GORYACHENKO")
#define psl pair <string, ll>
#define pls pair <ll, string>
#define x first
#define y second
#pragma GCC optimize("O3")
#define plll pair <pair <ll, ll>, ll>
#define pllll pair <pair <ll, ll>, pair <ll, ll> >
 
typedef long long ll;
 
typedef long double ld;
 
using namespace std;
 
const ll maxn = 21;
const ll inf = 1e9;

ll n, m, k, t, s;

ll A[maxn];

ll B[maxn];

ll st2[maxn];

ll solve(ll msk) {
	// cout << "SOLVE " << msk << endl;
	ll q, w;
	vector <ll> C(n);
	vector <bool> F(n); // is cyotn
	vector <ll> I;
	for (q = 0; q < n; q++) {
		I.pb(q);
		F[q] = ((msk & st2[q]) == 0);
		if (q % 2 != F[q]) {
			C[q] = B[q];
		}
		else {
			C[q] = A[q];
		}
		// cout << q << " " << F[q] << " " << A[q] << " " << B[q] << " C" << endl;
		// cout << C[q] << " ";
	}
	// cout << "C" << endl;
	// for (q = 0; q < n; q++) {
	// 	cout << C[q] << " ";
	// }
	// cout << endl;
	// cout << endl;
	ll cnt = 0;
	for (q = 0; q < n; q++) {
		for (w = 0; w < n - 1; w++) {
			if (C[I[w]] > C[I[w + 1]]) {
				swap(I[w], I[w + 1]);
				cnt++;
			}
		}
	}
	// for (q = 0; q < n; q++) {
	// 	for (w = 0; w < n - 1; w++) {
	// 		if (C[I[w]] == C[I[w + 1]]) {
	// 			if (F[I[w]] % 2 != w % 2 && F[I[w + 1]] % 2 == w % 2) {
	// 				swap(I[w], I[w + 1]);
	// 				cnt++;
	// 			}
	// 		}
	// 	}
	// }
	// cout << "I " << endl;
	// for (q = 0; q < n; q++) {
	// 	cout << I[q] << " ";
	// }
	// cout << endl;
	vector <ll> I1(n);
	for (q = 0; q < n; q++) {
		I1[I[q]] = q;
	}
	ll l = 0;
	vector <ll> CY;
	vector <ll> NC;
	for (q = 0; q < n; q++) {
		if (q != 0) {
			if (C[I[q]] != C[I[q - 1]]) {
				reverse(CY.begin(), CY.end());
				reverse(NC.begin(), NC.end());
				for (w = l; w < q; w++) {
					if (w % 2 == 0) {
						if (!CY.empty()) {
							I[w] = CY.back();
							CY.pop_back();
							cnt += abs(w - I1[I[w]]);
						}
						else {
							// cout << "w1 " << w << endl;
							return inf;
						}
					}
					else {
						if (!NC.empty()) {
							I[w] = NC.back();
							NC.pop_back();
						}
						else {
							// cout << "w2 " << w << endl;
							return inf;
						}
					}
				}
				l = q;
			}
		}
		if (1) {
			if (!F[I[q]]) {
				CY.pb(I[q]);
			}
			else {
				NC.pb(I[q]);
			}
		}
	}
	reverse(CY.begin(), CY.end());
	reverse(NC.begin(), NC.end());
	for (w = l; w < q; w++) {
		if (w % 2 == 0) {
			if (!CY.empty()) {
				I[w] = CY.back();
				CY.pop_back();
				cnt += abs(w - I1[I[w]]);
			}
			else {
				// cout << "w3 " << w << endl;
				return inf;
			}
		}
		else {
			if (!NC.empty()) {
				I[w] = NC.back();
				NC.pop_back();
			}
			else {
				// cout << "w4 " << w << endl;
				return inf;
			}
		}
	}
	l = q;
	for (q = 0; q < n; q++) {
		if (F[I[q]] != q % 2) {
			return inf;
		}
	}
	return cnt;
}

int main()
{
	pyshnapyshnakaa;
	ll q, w, e, a, b, c;
	st2[0] = 1;
	for (q = 1; q < maxn; q++) {
		st2[q] = st2[q - 1] * 2;
	}
	cin >> n;
	for (q = 0; q < n; q++) {
		cin >> A[q];
	}
	for (q = 0; q < n; q++) {
		cin >> B[q];
	}
	ll ans = inf;
	for (ll msk = 0; msk < st2[n]; msk++) {
		if (__builtin_popcount(msk) != (n + 1) / 2) {
			continue;
		}
		ans = min(ans, solve(msk));
	}
	if (ans == inf) {
		cout << -1;
		return 0;
	}
	cout << ans;
	return 0;
}


Measured memory_bytes: 256