#include <iostream>
#include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <cstring>
#include <deque>
#include <functional>
#include <initializer_list>
#include <math.h>
#include <map>
#include <random>
#include <set>
#include <stack>
#include <tuple>
#include <queue>
#include <vector>

#define FOR(i, a, b) for(int (i) = (a); (i) < (b); ++(i))
#define rFOR(i, a, b) for(int (i) = (b); (i) >= (a); --(i))
#define REP(i, n) FOR(i, 0, n)
#define rREP(i, n) rFOR(i, 0, (n-1))
#define SORT(A) std::sort((A).begin(), (A).end())
#define ALL(A) (A).begin(), (A).end()
// 座標圧縮 (for vector) : ソートしてから使うのが一般的 ; SORT(A) => COORDINATE_COMPRESSION(A)
#define COORDINATE_COMPRESSION(A) (A).erase(unique((A).begin(),(A).end()),(A).end())

using lli = long long int;
using pii = std::pair<int, int>;

// グリッド上の縦横移動
constexpr std::array<std::pair<int, int>, 4> dxdy = {
    std::pair<int, int>( 1,  0),
    std::pair<int, int>(-1,  0),
    std::pair<int, int>( 0,  1),
    std::pair<int, int>( 0, -1)
};

void VintOut(std::vector<int>& A){
    const int n = A.size();
    if(n == 0){putchar('\n'); return;}
    printf("%d", A[0]);
    for(int i = 1; i < n; ++i) printf(" %d", A[i]);
    putchar('\n');
}
void VintOut(std::vector<long long int>& A){
    const int n = A.size();
    if(n == 0){ putchar('\n'); return;}
    printf("%lld", A[0]);
    for(int i = 1; i < n; ++i) printf(" %lld", A[i]);
    putchar('\n');
}

template <typename T>
inline bool chmin(T& a, T b){
    if(b < a){ a = b; return true;}
    return false;
}

template <typename T>
inline bool chmax(T& a, T b){
    if(a < b){ a = b; return true;}
    return false;
}

inline bool isIn(int x, int y, int H, int W){
    return 0 <= x and x < H and 0 <= y and y < W;
}
inline bool bitUP(int state, int k){ return (state >> k) & 1; }
inline bool bitUP(long long int state, int k){ return (state >> k) & 1;}

// z-algorithm
template <class T> std::vector<int> z_algorithm(const T &str) {
    const int n = str.size();
    std::vector<int> resOfCP(n); resOfCP[0] = n;
    int i = 1, j = 0;
    while (i < n) {
        while (i + j < n and str[j] == str[i + j]) ++j;
        resOfCP[i] = j;
        if (j == 0) { ++i; continue;}
        int k = 1;
        while (i + k < n and k + resOfCP[k] < j) resOfCP[i + k] = resOfCP[k], ++k;
        i += k; j -= k;
    }
    return resOfCP;
}


// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~


constexpr int inf = 1e9 + 334 + 810 + 1919;
std::vector<int> A, B;
std::vector<std::pair<int, int>> Odd, Even;
std::vector<int> Idx;

int main(void){
    int n; scanf("%d", &n);
    A.resize(n); REP(i, n) scanf("%d", &A[i]);
    B.resize(n); REP(i, n) scanf("%d", &B[i]);


    Odd.resize(n); Even.resize(n);
    Idx.resize(n);

    const int Nodd = n >> 1;
    const int Neven = n - Nodd;
    int N = 1 << n;

    int res = inf;
    REP(state, N){
        int odd = 0, even = 0;
        REP(i, n){
            if(bitUP(state, i)){ // 偶奇反転
                if(i % 2 == 0) Odd[odd++] = {B[i], i};
                else Even[even++] = {B[i], i};
            }
            else{
                if(i % 2 == 0) Even[even++] = {A[i], i};
                else Odd[odd++] = {A[i], i};
            }
        }
        if(odd != Nodd or even != Neven) continue;

        // 0 1 2 3 4 ... n - 1の順に並べる
        std::sort( Odd.begin(),  Odd.begin() + odd );
        std::sort(Even.begin(), Even.begin() + even);


        bool isSorted = true;
        for(int i = 0; i < odd; ++i){
            if(Even[i].first > Odd[i].first){isSorted = false; break;}
            if(i + 1 < even and Odd[i].first > Even[i+1].first){isSorted = false; break;}
        }
        if(not isSorted) continue;
        
        REP(i, odd) Idx[Odd[i].second] = 2 * i + 1;
        REP(i, even) Idx[Even[i].second] = 2 * i;
        
        // 転倒数を数える
        int cnt = 0;
        REP(i, n) for(int j = i + 1; j < n; ++j) if(Idx[i] > Idx[j]) cnt++;
        if(res > cnt) res = cnt;
    }
    if(res == inf) puts("-1");
    else printf("%d\n", res);




    return 0;
}

Measured memory_bytes: 384