import std.stdio, std.algorithm, std.conv, std.array, std.string, std.math, std.typecons, std.numeric, std.container, std.range;
import core.bitop;

alias X = Tuple!(int, "n", int, "f", int, "t");

void main()
{
    auto N = readln.chomp.to!int;
    auto AS = readln.split.to!(int[]);
    auto BS = readln.split.to!(int[]);
    int r = int.max;
    foreach (b; 0..(1<<N)) if (popcnt(b)%2 == 0) {
        X[] xs;
        foreach (i; 0..N) {
            X x;
            if (b&(1<<i)) {
                x.n = BS[i];
                x.t = 1;
            } else {
                x.n = AS[i];
            }
            xs ~= x;
        }
        int rr;
        foreach (i; 1..N) {
            auto j = i;
            while (j > 0 && xs[j-1].n >= xs[j].n) {
                if (xs[j-1].n == xs[j].n && xs[j-1].f%2 == xs[j-1].t) break;
                ++rr;
                swap(xs[j-1], xs[j]);
                ++xs[j-1].f;
                ++xs[j].f;
                --j;
            }
        }
        foreach (i; 0..N) {
            if (i && xs[i-1].n > xs[i].n) goto ng;
            if (xs[i].f%2 != xs[i].t) goto ng;
        }
        r = min(r, rr);
        ng:
    }
    writeln(r == int.max ? -1 : r);
}