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;


void main() {
    int N;
    scan(N);
    auto a = readln.split.to!(int[]);
    auto b = readln.split.to!(int[]);

    // dp(s, x) = (sに含まれるカードを左からソートした状態で詰めて最後がxになるときの最小操作回数)
    auto dp = new int[][](1 << N, 51);
    fillAll(dp, inf);
    dp[0][0] = 0;

    foreach (s ; 0 .. 1 << N) {
        foreach (x ; 0 .. 51) {
            if (dp[s][x] == inf) continue;
            int p = 0;
            int i = s.popcnt;

            foreach (j ; 0 .. N) if (!(s & 1 << j)) {
                int pos = p + i;
                p++;

                int y = abs(j - i) % 2 == 0 ? a[j] : b[j];

                debug {
                    writefln("pos: %s, y: %s", pos, y);
                }

                if (y >= x) {
                    chmin(dp[s | 1 << j][y],
                        dp[s][x] + abs(pos - i));
                }
            }
        }
    }

    debug {
        writefln("%(%s\n%)", dp);
    }

    int ans = inf;
    foreach (x ; 0 .. 51) {
        chmin(ans, dp[(1 << N) - 1][x]);
    }

    ans = ans < inf ? ans : -1;

    writeln(ans);
}



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);
}
