import std.stdio, std.conv, std.string, std.array, std.range, std.algorithm, std.container;
import std.math, std.random, std.bigint, std.datetime, std.format;
void main(string[] args){ if(args.length > 1) if(args[1] == "-debug") DEBUG = 1; solve(); }
void log()(){ writeln(""); } void log(T, A ...)(T t, lazy A a){ if(DEBUG) write(t, " "), log(a); } bool DEBUG = 0; 
string rstring(){ static string[] ss; while(!ss.length) ss = readln.chomp.split; string res = ss[0]; ss.popFront; return res; }
T rtype(T)(){ return rstring.to!T; } alias rint = rtype!int, rlong = rtype!long, rreal = rtype!real;
T[] rtypes(T)(int n){ return n.iota.map!(i => rtype!T()).array; } alias rint = rtypes!int, rlong = rtypes!long, rreal = rtypes!real;
T[][] rtypess(T)(int n, int m){ return n.iota.map!(i => rtypes!T(m)).array; } alias rint = rtypess!int, rlong = rtypess!long, rreal = rtypess!real;
T chmin(T)(ref T x, T y){ if(x > y) x = y; return x; } T chmax(T)(ref T x, T y){ if(x < y) x = y; return x; }

// ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- //

void solve(){
	int n = rint;
	int[] as = rint(n), bs = rint(n);

	X[] xs;
	foreach(i; 0 .. n) xs ~= X(i, as[i], bs[i]);
	log("xs:", xs);

	long infty = 18 * 1_000_000_000;
	long ans = infty;
	for(long m = 0; m < (1L<<n); m ++){
		log("m:", m);

		U[] us;
		foreach(i, x; xs) if((1L<<i) & m) us ~= U(1, x.a); else us ~= U(0, x.b);
		log("us:", us);

		U[] vs;
		foreach(u; us) vs ~= u;
		vs.sort!"a.value<b.value"();
		log("vs:", vs);

		// それが実現可能か調べる
		// vsでの位置より右で偶奇の合ってる場所から持って来れるならよい
		// 実現可能なら最短の手数（バブルソート）
		long tmpans = 0;
		foreach(j, v; vs){
			long tmp = -1;
			bool f = 1;
			log("j:", j);
			log("vs:", vs);
			foreach(i, u; us){
				if(u.value >= 0) tmp += 1;
				if(u.isA && ((j - i) % 2 != 0)) continue;
				if(!u.isA && ((j - i) % 2 == 0)) continue;
				if(u.value != v.value) continue;
				tmpans += tmp;
				log("i:", i, "tmp:", tmp, "tmpans:", tmpans);
				us[i] = U(0, -1);
				f = 0;
				break;
			}
			if(f){
				tmpans = infty;
				log("failed");
				break;
			}
			log("us:", us, "tmp:", tmp, "tmpans:", tmpans);
		}
		if(tmpans < infty) log("success", tmpans);
		ans = min(ans, tmpans);
		log("ans:", ans);
	}

	if(ans >= infty) ans = -1;
	ans.writeln;

}
struct X{
	int pos;
	int a, b;
}
struct U{
	bool isA;
	int value;
}