// D - Swap and Flip
#include <bits/stdc++.h>

using namespace std;

#define	INF	1000000000

int main(int argc, char *argv[])
{
	ios::sync_with_stdio(false); cin.tie(0);

	int n;
	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<vector<int> > dp(1 << n, vector<int>(n, INF));
	for (int i = 0; i < n; i++) dp[1 << i][i] = i;
	for (int k = 0; k < (1 << n); k++)
		for (int l = 0; l < n; l++) {
			if ((k & (1 << l)) == 0) continue;
			int p = k ^ (1 << l);
			int c = __builtin_popcount(p);
			int x = abs(l - c) % 2 == 0 ? a[l] : b[l];
			int d = __builtin_popcount((~k) & ((1 << l) - 1));
          for (int i = 0; i < n; i++) {
            if ((p & (1 << i)) == 0) continue;
            int y = abs(i - c + 1) % 2 == 0 ? a[i] : b[i];
            if (y <= x) dp[k][l] = min(dp[k][l], dp[p][i] + d);
          }
		}
	int ans = INF;
	for (int i = 0; i < n; i++) ans = min(ans, dp[(1 << n) - 1][i]);

	cout << (ans < INF ? ans : -1) << endl;

	return 0;
}
