#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
using ll = long long;
const ll INF = (int)1e9;

const int N = 18;
const int V = 50;
int dp[1 << N][V+1];
int as[N];
int bs[N];
int off[N][N];

void cap(int& v, int off) {
	if (v > off) v = off;
}

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(0);

	int n;
	cin >> n;
	for (int i = 0; i < n; ++i) cin >> as[i];
	for (int i = 0; i < n; ++i) cin >> bs[i];
	for (int i = 0; i < n; ++i) {
		for (int j = 0; j < n; ++j) {
			off[i][j] = (i % 2 == j % 2) ? as[j] : bs[j];
		}
	}

	int h = 1 << n;
	for (int m = 0; m < h; ++m) {
		for (int j = 0; j <= V; ++j) dp[m][j] = INF;
	}
	dp[0][0] = 0;
	
	for (int m = 0; m < h; ++m) {
		int i = __builtin_popcount(m);
		for (int v = 0; v <= V; ++v) {
			int d = 0;
			for (int j = 0; j < n; ++j) {
				if (m & (1 << j)) continue;
				if (off[i][j] >= v) cap(dp[m | (1 << j)][off[i][j]], dp[m][v] + d);
				++d;
			}
		}
	}

	int res = INF;
	for (int v = 0; v <= V; ++v) res = min(res, dp[h-1][v]);
	cout << (res >= INF ? -1 : res) << '\n';
}
