#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const static ll INF = 1e15;
// __uint128_t



int main(){
    ll N; cin >> N;
    vector<ll> A(N), B(N);
    for(int i = 0; i < N; i++) cin >> A[i];
    for(int i = 0; i < N; i++) cin >> B[i];

    vector<vector<ll>> DP((1<<N)+1, vector<ll>(55, INF)); DP[0][0] = 0;
    for(int i = 0; i < (1<<N) ; i++){
        bitset<20> b = i;
        ll c = b.count();


        ll p = 0; // 立っているビットが左にソートされた上で、自分がどの位置にいるか
        for(int j = N-1; j >= 0; j--){
            if(b[j] == 1) {p++; continue;}
            for(int k = 0; k <= 50; k++){
                if(DP[i][k] == INF) continue;
                bitset<20> b2 = 0; b2[j] = 1;
                ll n;
                if( abs(c-j)%2 == 0) n = A[j];
                else n = B[j];
                if(n >= k) { //照準にならないなら棄却
                    DP[(b|b2).to_ullong()][n] = min(DP[i][k] + abs(c-(j+p)), DP[(b|b2).to_ullong()][n]);
                }
            }
        }
    }
    ll ans = INF;
    for(int i = 0; i <= 50; i++) ans = min(ans, DP[(1<<N)-1][i]);
    if(ans == INF) cout << -1 << endl;
    else cout << ans << endl;



}