#include<bits/stdc++.h>
#include<boost/variant.hpp>
using namespace std;
typedef long long ll;
typedef vector<boost::variant<bool, ll, int, string, double, char*, const char*>> any;
template<typename T> inline void pr(const vector<T> &xs){
	for(int i=0; i<xs.size()-1; i++) cout<<xs[i]<<" ";
	(xs.empty()?cout:(cout<<xs[xs.size()-1]))<<endl;
}
#ifdef DEBUG
#define debug(...) pr(any{__VA_ARGS__})
#define debugv(x) pr((x))
#else
#define debug(...)
#define debugv(x)
#endif

template <class T>
struct Bit{
	std::vector<T> v;
	int n;
	Bit(int n_): n(n_){ v.assign(n_, 0); }
	// i must be 0 <= i < n
	T sum(int i){
		T s=0;
		while(i>0){ s += v[i]; i -= i & -i; }
		return s;
	}
	// i must be 1 <= i < n
	void add(int i, T x){
		while(i < n){ v[i] += x; i += i & -i; }
	}
};

// v: permutation of (1, ... , n)
int crossing(std::vector<int> &v){
	Bit<int> bit(v.size()+1);
	int count = 0;
	for(int i=0; i<v.size(); i++){
		count += i - bit.sum(v[i]);
		bit.add(v[i], 1);
	}
	return count;
}

int N;
int dfs(vector<int> &p, vector<bool> &used, int x, vector<int> &a, vector<int> &b){
	int ret = x;
	if(p.size()==N) {
		return crossing(p);
	}

	debug(x);
	if(p.size() >= 2) {
		vector<pair<int, int>> cp;
		for(int i=0; i<p.size(); i++) cp.emplace_back(p[i], i);
		sort(cp.begin(), cp.end());
		vector<int> c(p.size());
		for(int i=0; i<p.size(); i++) c[cp[i].second] = i+1;
		debugv(c);
		debugv(p);
		int cr = crossing(c);
		debug(cr, x);
		if(cr >= x) return x;
	}

	for(int i=0; i<N; i++){
		//debug((int)p.size(), i);
		if(used[i]) continue;
		int val;
		if(i%2 == p.size()%2){
			val = a[i];
		} else {
			val = b[i];
		}

		if(p.size() > 0){
			int last_idx = p[p.size()-1]-1;
			int last_val;
			if(last_idx%2==(p.size()-1)%2){
				last_val = a[last_idx];
			} else {
				last_val = b[last_idx];
			}
			if(val < last_val) continue;
		}

		p.push_back(i+1);
		used[i] = true;
		ret = min(ret, dfs(p, used, ret, a, b));
		p.pop_back();
		used[i] = false;
	}
	return ret;
}

int main(){
	cin >> N;
	vector<int> A(N), B(N);
	for(int i=0; i<N; i++) cin >> A[i];
	for(int i=0; i<N; i++) cin >> B[i];

	vector<int> p;
	vector<bool> used(N);
	int ans = dfs(p, used, 1e9, A, B);
	if(ans==1e9) cout << -1 << endl;
	else cout << ans << endl;

	return 0;
}
