#include <bits/stdc++.h>
using namespace std;
#define INF 10000

int N;
int A[20], B[20];
int dp[1<<20][20];

int main() {
    cin >> N;
    for (int i=0; i<N; i++) cin >> A[i];
    for (int i=0; i<N; i++) cin >> B[i];
    for (int i=0; i<(1<<N); i++) for (int j=0; j<N; j++) dp[i][j] = INF;
    for (int i=0; i<N; i++) dp[1<<i][i] = 0;
    
    for (int S=0; S<(1<<N); S++) {
        int cnt = 0;
        for (int i=0; i<N; i++) if ((S>>i)&1) cnt++;
        
        for (int i=0; i<N; i++) {
            int cost = cnt;
            
            for (int j=0; j<N; j++) {
                if (!((S>>j)&1)) {
                    int n1 = (i-(cnt-1))%2==0 ? A[i] : B[i];
                    int n2 = (j-cnt)%2==0 ? A[j] : B[j];
                    if (n1>n2) continue;
                    dp[S|(1<<j)][j] = min(dp[S|(1<<j)][j], dp[S][i]+cost);
                }
                else cost--;
            }
        }
    }
    
    int ans = INF;
    for (int i=0; i<N; i++) ans = min(ans, dp[(1<<N)-1][i]);
    cout << (ans==INF ? -1 : ans) << endl;
}