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

enum inf = 1_001_001_001;
enum infl = 1_001_001_001_001_001_001L;

alias Card = Tuple!(int, "x", bool, "h");

void main() {
    int N;
    scan(N);

    auto a = readln.split.to!(int[]);
    auto b = readln.split.to!(int[]);

    if (N == 1) {
        writeln(0);
        return;
    }

    auto ans = inf;

    foreach (set ; 0 .. 1 << N) {
        Card[] cs;

        foreach (i ; 0 .. N) {
            if (set & 1 << i) {
                cs ~= Card(a[i], 1);
            }
            else {
                cs ~= Card(b[i], 0);
            }
        }

        chmin(ans, solve(N, cs));
    }

    writeln(ans == inf ? -1 : ans);
}


int solve(int N, Card[] cs) {
    int res;

    foreach (i ; 0 .. N) {
        foreach_reverse (j ; i + 1 .. N) {
            if (cs[j - 1].x > cs[j].x) {
                swap(cs[j - 1], cs[j]);
                cs[j - 1].h ^= 1;
                cs[j].h ^= 1;
                res++;
            }
        }
    }

    foreach (i ; 0 .. N - 2) {
        assert(cs[i].x <= cs[i + 1].x);

        if (!cs[i].h) {
            if (cs[i].x != cs[i + 1].x) {
                return inf;
            }
            if (!cs[i + 1].h) {
                res++;
                cs[i + 1].h ^= 1;
            }
            else if (cs[i + 2].x == cs[i].x && cs[i + 2].h) {
                res += 2;
                cs[i + 2].h ^= 1;
            }
            else {
                return inf;
            }
        }
    }

    if (cs[N - 2].h && cs[N - 1].h) {
        return res;
    }
    else if (cs[N - 2].x == cs[N - 1].x && !cs[N - 2].h && !cs[N - 1].h) {
        res++;
    }
    else {
        return inf;
    }

    return res;
}



void scan(T...)(ref T args) {
    auto line = readln.split;
    foreach (ref arg; args) {
        arg = line.front.to!(typeof(arg));
        line.popFront;
    }
    assert(line.empty);
}

void fillAll(R, T)(ref R arr, T value) {
    static if (is(typeof(arr[] = value))) {
        arr[] = value;
    }
    else {
        foreach (ref e; arr) {
            fillAll(e, value);
        }
    }
}

bool chmin(T, U...)(ref T x, U args) {
    bool isChanged;
    foreach (arg; args) if (x > arg) {
        x = arg;
        isChanged = true;
    }
    return isChanged;
}

bool chmax(T, U...)(ref T x, U args) {
    bool isChanged;
    foreach (arg; args) if (x < arg) {
        x = arg;
        isChanged = true;
    }
    return isChanged;
}

void yes(bool ok, string y = "Yes", string n = "No") {
    return writeln(ok ? y : n);
}
