#include<iostream>
#include<algorithm>
#include<vector>
#include<tuple>
#include<queue>
#include<map>
#include<functional>

using namespace std;

typedef long long ll;
typedef tuple < ll, int, bool > T3;//値, もともとの位置, 表裏(trueなら裏)

template <class Monoid> struct SegTree {
	int N;
	vector<Monoid> node;
	std::function<Monoid(Monoid, Monoid)> operation;
	Monoid unit;//単位元

	std::function<bool(Monoid, Monoid)> comp;
	Monoid not_find_sgn;

	SegTree(vector<Monoid>& data, std::function<Monoid(Monoid, Monoid)> op, Monoid U) {
		//データ　演算　単位元
		operation = op;
		unit = U;
		int size = data.size();
		N = 1;
		while (N < size)N <<= 1;
		node.resize(2 * N - 1, unit);

		for (int i = 0; i < size; i++) {
			node[i + N - 1] = data[i];
		}

		for (int i = N - 2; i >= 0; i--) {
			node[i] = operation(node[i * 2 + 1], node[i * 2 + 2]);
		}
	}

	void update(int pos, Monoid val) {
		pos += N - 1;
		node[pos] = val;
		while (pos > 0) {
			pos = (pos - 1) / 2;
			node[pos] = operation(node[pos * 2 + 1], node[pos * 2 + 2]);
		}
	}

	Monoid getval(int a, int b, int idx, int l, int r = -1) {
		//[a, b)を求める。　使い方はgetval(a, b, );
		if (r == -1)r = N;
		if (b <= l || r <= a)return unit;
		if (a <= l && r <= b)return node[idx];
		Monoid left = getval(a, b, idx * 2 + 1, l, (l + r) / 2);
		Monoid right = getval(a, b, idx * 2 + 2, (l + r) / 2, r);
		return operation(left, right);
	}

	Monoid getval(int a, int b) {
		//ラッパー。
		return getval(a, b, 0, 0, -1);
	}

};

int N;
int A[50], B[50];

int tentousu(vector<int>& tmp) {
	vector<int> t(50 + 1, 0);
	SegTree<int> st(t, [](int a, int b) {return a + b; }, 0);
	int ret = 0;
	for (int i = 0; i < tmp.size(); i++) {
		ret += st.getval(tmp[i] + 1, 51);
		st.update(tmp[i], 1);
	}
	return ret;
}

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

	vector<vector<T3>> candidate;
	for (int bit = 0; bit < (1 << N); bit++) {
		vector<T3> tmp;
		int cnt = 0;
		for (int i = 0; i < N; i++) {
			if ((bit >> i) & 1) {
				//裏返す
				cnt++;
				tmp.push_back(make_tuple(B[i], i, true));
			}
			else {
				tmp.push_back(make_tuple(A[i], i, false));
			}
		}
		if (cnt % 2 != 0)continue;
		sort(tmp.begin(), tmp.end());

		candidate.push_back(tmp);
	}

	int ans = 1145141919;
	for (int i = 0; i < candidate.size(); i++) {
		
		//最終的に奇数番目か偶数番目かのどれになるかによって2つに分ける
		map<int, vector<int>> c1, c2, c3, c4;
		
		for (int j = 0; j < N; j++) {
			if (j % 2 == 0) {
				c2[get<0>(candidate[i][j])].push_back(j);
			}
			else {
				c4[get<0>(candidate[i][j])].push_back(j);
			}
			if ((get<1>(candidate[i][j]) + get<2>(candidate[i][j])) % 2 == 0) {
				c1[get<0>(candidate[i][j])].push_back(get<1>(candidate[i][j]));
			}
			else {
				c3[get<0>(candidate[i][j])].push_back(get<1>(candidate[i][j]));
			}
		}

		vector<int> tmp(N, -1);//これの転倒数を求める
		bool isok = true;
		for (auto ele : c1) {
			if (c1[ele.first].size() != c2[ele.first].size())isok = false;
			else {
				for (int j = 0; j < ele.second.size(); j++) {
					tmp[c2[ele.first][j]] = c1[ele.first][j];
				}
			}
		}
		for (auto ele : c3) {
			if (c3[ele.first].size() != c4[ele.first].size())isok = false;
			else {
				for (int j = 0; j < ele.second.size(); j++) {
					tmp[c4[ele.first][j]] = c3[ele.first][j];
				}
			}
		}

		if (!isok)continue;

		ans = min(ans, tentousu(tmp));
		
	}

	if (ans == 1145141919)cout << -1 << endl;
	else cout << ans << endl;

	return 0;
}

Measured memory_bytes: 44336