#include <cstdio>
#include <vector>
using namespace std;
int a[20], b[20], c[20];
int dp[2][1<<18][18];
inline int f(int j, int k) {
	return (j - k) & 1 ? b[k] : a[k];
}
inline void upd(int &v, int x) {
	if (x && (!v || v > x)) v = x;
}
int main() {
	int n;
	scanf("%d", &n);
	for (int i = 0; i < n; i++) {
		scanf("%d", &a[i]);
	}
	for (int i = 0; i < n; i++) {
		scanf("%d", &b[i]);
	}
	int y = 0, z = 1;
	for (int i = 0; i < n; i++) {
		dp[y][1<<i][i] = i + 1;
	}
	for (int i = 1; i < n; i++) {
		for (int j = 0; j < 1 << n; j++) {
			for (int k = 0; k < n; k++) {
				dp[z][j][k] = 0;
			}
		}
		for (int j = 0; j < 1 << n; j++) {
			int m = 0;
			for (int k = 0; k < n; k++) {
				if (!(j >> k & 1)) {
					c[m++] = k;
				}
			}
			for (int k = 0; k < n; k++) {
				if (!(j >> k & 1)) continue;
				if (!dp[y][j][k]) continue;
				int la = f(i - 1, k);
				for (int l = 0; l < m; l++) {
					int t = f(i, c[l]);
					if (la > t) continue;
					upd(dp[z][j|(1<<c[l])][c[l]], dp[y][j][k] + l);
				}
			}
		}
		y = 1 - y;
		z = 1 - z;
	}
	int ans = 0;
	for (int i = 0; i < n; i++) {
		upd(ans, dp[y][(1<<n)-1][i]);
	}
	printf("%d\n", ans - 1);
	return 0;
}
