#include<cstdio>
#include<cmath>
#include<cstring>
#include<algorithm>
#include<queue>
#include<map>
#include<vector>
#include<functional>
#include <random>
#include<iostream>
#include<iomanip>
using namespace std;

int N;
int num;
int A[18], B[18];
pair<pair<int, int>, int> cards[18];
pair<pair<int, int>, int> cards_A[9];
pair<pair<int, int>, int> cards_B[9];

int comb[18];


int get_next_comb(void) {
	int right_most=-1;
	int sonomigi = 0;
	/*まず、右が0であるような最も右にある1を見つける*/
	for (int i = num * 2 - 2; i >= 0;i--) {
		if (comb[i + 1] == 0 && comb[i] == 1) {
			right_most = i;
			break;
		}
	}

	if (right_most == -1) {
		return 0; /*終わり*/
	}

	for (int i = right_most; i < num * 2; i++) {
		if (comb[i] == 1) {
			sonomigi++;
		}
	}
	comb[right_most] = 0;
	for (int i = right_most + 1; i < right_most + 1 + sonomigi; i++) {
		comb[i] = 1;
	}
	for (int i = right_most + 1 + sonomigi; i < num * 2; i++) {
		comb[i] = 0;
	}
	
	return 1;
}

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

	for (int i = 0; i < N; i++) {
		cards[i].first.first = A[i];
		cards[i].first.second = B[i];
		cards[i].second = i;
	}


	if (N % 2 == 1) {
		cards[N].first.first = 100;
		cards[N].first.second = 100;
		cards[N].second = N;
	}

	num = (N + 1) / 2;


	for (int i = 0; i < num; i++) {
		comb[i] = 1; comb[i + num] = 0;
	}

	int ans = 10000;
	int possible = 0;
	int madayaru = 1;
	while (madayaru) {
		int A = 0; int B = 0;
		for (int i = 0; i < num * 2; i++) {
			if (comb[i] == 1) {
				if (i % 2 == 0) {
					cards_A[A].first.first = cards[i].first.first;
					cards_A[A].first.second = cards[i].first.second;
					cards_A[A].second = cards[i].second;
				}
				else {
					cards_A[A].first.first = cards[i].first.second;
					cards_A[A].first.second = cards[i].first.first;
					cards_A[A].second = cards[i].second;
				}
				A++;
				
			}
			else {
				if (i % 2 == 0) {
					cards_B[B].first.first = cards[i].first.first;
					cards_B[B].first.second = cards[i].first.second;
					cards_B[B].second = cards[i].second;
				}
				else {
					cards_B[B].first.first = cards[i].first.second;
					cards_B[B].first.second = cards[i].first.first;
					cards_B[B].second = cards[i].second;
				}
				B++;
			}
		}

		for (int i = 0; i < num; i++) {
			int sw = cards_B[i].first.first;
			cards_B[i].first.first = cards_B[i].first.second;
			cards_B[i].first.second = sw;
		}

		for (int i = 0; i < num; i++) {
			int sw = cards_A[i].first.second;
			cards_A[i].first.second = cards_A[i].second;
			cards_A[i].second = sw;
		}

		for (int i = 0; i < num; i++) {
			int sw = cards_B[i].first.second;
			cards_B[i].first.second = cards_B[i].second;
			cards_B[i].second = sw;
		}

		sort(cards_A, cards_A + num);
		sort(cards_B, cards_B + num);

		for (int i = 0; i < num; i++) {
			int sw = cards_A[i].first.second;
			cards_A[i].first.second = cards_A[i].second;
			cards_A[i].second = sw;
		}

		for (int i = 0; i < num; i++) {
			int sw = cards_B[i].first.second;
			cards_B[i].first.second = cards_B[i].second;
			cards_B[i].second = sw;
		}

		for (int i = 0; i < num; i++) {
			int sw = cards_B[i].first.first;
			cards_B[i].first.first = cards_B[i].first.second;
			cards_B[i].first.second = sw;
		}

		/*
		for (int i = 0; i < num; i++) {
			cout << cards_A[i].first.first << " " << cards_B[i].first.second << " ";
		}
		cout << "\n";
		*/

		int tmp = 0;
		int success = 1;
		for (int i = 0; i < num; i++) {
			if (tmp <= cards_A[i].first.first && cards_A[i].first.first <= cards_B[i].first.second) {
				tmp = cards_B[i].first.second;
			}
			else {
				success = 0;
			}
		}
		if (success == 1) {

			possible = 1;
			/*条件を満たすので、逆転数を計算する*/
			int rev = 0;
			int arr[18];
			for (int i = 0; i < num; i++) {
				arr[2 * i] = cards_A[i].second;
				arr[2 * i + 1] = cards_B[i].second;
			}
			for (int i = 0; i < num * 2; i++) {
				for (int j = i + 1; j < num * 2; j++) {
					if (arr[i] > arr[j]) {
						rev++;
					}
				}
			}
			if (ans > rev) { ans = rev; }
		}
		madayaru = get_next_comb();
	}

	if (possible == 0) {
		cout << "-1\n";
	}
	else {
		cout << ans;
	}

}

Measured memory_bytes: 256