#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC optimize("unroll-loops")
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<math.h>
#include<iomanip>
#include<set>
#include<numeric>
#include<cstring>
#include<cstdio>
#include<functional>
#include<bitset>
#include<limits.h>
#include<cassert>
#include<iterator>
#include<complex>
#include<stack>
#include<unordered_map>
#include<unordered_set>
#include<time.h>
#include<random>

using namespace std;

#define REP(i, n) for(int i = 0;i < n;++i)
#define REPR(i, n) for(int i = n-1;i >= 0;--i)
#define FOR(i, m, n) for(int i = m;i < n;++i)
#define FORR(i, m, n) for(int i = m-1;i >= n;--i)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define REVERSE(v,n) reverse(v,v+n);
#define VREVERSE(v) reverse(v.begin(), v.end())
#define ll long long
#define pb(a) push_back
#define print(x) cout<<(x)<<endl
#define pe(x) cout<<(x)<<" "
#define DEBUG(x) cout<<#x<<": "<<x<<endl
#define lb(v,n) lower_bound(v.begin(), v.end(), n)
#define ub(v,n) upper_bound(v.begin(), v.end(), n)
#define int long long
#define all(x) (x).begin(), (x).end()
#define print_space(v) REP(i,v.size())cout << v[i] << ((i == v.size() - 1) ? "\n" : " ")
template<typename T1, typename T2> inline void chmin(T1 & a, T2 b) { if (a > b) a = b; }
template<typename T1, typename T2> inline void chmax(T1& a, T2 b) { if (a < b) a = b; }
typedef pair<int, int>P;
const int MOD = 1e9 + 7; const int MAX = 101;
const double pi = acos(-1); const double EPS = 1e-12;
const ll INF = 2e18;


double dist(double x1, double x2, double y1, double y2) {
	return sqrt((x1 - x2)*(x1 - x2) + (y1 - y2)*(y1 - y2));
}
double dist(P &p1, P &p2) {
	double x1 = p1.first, x2 = p2.first, y1 = p1.second, y2 = p2.second;
	return sqrt((x1 - x2)*(x1 - x2) + (y1 - y2)*(y1 - y2));
}


int BIT[MAX], M = 100;//Nは要素数
int bitsum(int i) {
	int s = 0;
	while (i > 0) {
		s += BIT[i];
		i = i & (i - 1);
	}
	return s;
}
void bitadd(int i, int x) {
	while (i <= M) {
		BIT[i] += x;
		i += i & -i;
	}
}
void test() {
	int N; cin >> N;
	vector<int>A(N);
	REP(i, N)cin >> A[i];
	int res = 0;
	REP(j, N) {
		res += j - bitsum(A[j]);
		bitadd(A[j], 1);
	}
	print(res);
}
void solve() {
	//test(); return;
	int N;
	cin >> N;
	vector<int>A(N), B(N);
	REP(i, N) {
		cin >> A[i];
	}
	REP(i, N) {
		cin >> B[i];
	}
	//print(-1); return;
	int perm[20] = {};
	REP(i, N) {
		if (i < (N + 1) / 2)perm[i] = 0;
		else perm[i] = 1;
	}
	int cnt = 0;
	int ans = INF;
	do {
		cnt++;
		vector<int>v(N);
		vector<int>r, b;
		vector<P>vp;
		REP(i, N) {
			int id = perm[i] + i;
			if (id % 2 == 0)v[i] = A[i];
			else v[i] = B[i];
			if (perm[i] == 0)b.push_back(v[i]);
			else r.push_back(v[i]);
			//vp.push_back({ v[i],perm[i] });
		}

		//print("debug");
		//print_space(b);
		//print_space(r);
		VSORT(b); VSORT(r);
		vector<int>v2;
		REP(i, N) {
			if (i % 2 == 0)v2.push_back(b[i / 2]);
			else v2.push_back(r[i / 2]);
		}
		int res = 0;
		vector<int>idx(N);
		vector<bool>used(N);
		REP(i, N) {
			REP(j, N) {
				if (used[j])continue;
				if (i % 2 == perm[j] && v2[i] == v[j]) {
					idx[j] = i + 1;
					used[j] = true;
					break;
				}

			}
		}
		REP(i, N)if (!used[i])goto END;
		FOR(i, 1, N) {
			if (v2[i] < v2[i - 1])goto END;
		}

		REP(j, 101)BIT[j] = 0;
		REP(j, N) {
			res += j - bitsum(idx[j]);
			bitadd(idx[j], 1);
		}
		//DEBUG(res);
		ans = min(ans, res);
	END:;
	} while (next_permutation(perm, perm + N));;
	if (ans == INF)print(-1);
	else print(ans);

	//DEBUG(cnt);
}

signed main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	//int q;cin>>q;
	//while(q--)
	solve();
}




Measured memory_bytes: 256