#include <bits/stdc++.h>
using namespace std;
#define R(i,n) for(int i = 0; i < (n); i++)

signed main(){
    int n,a=1e9,c[2][20];
    cin>>n;
    R(i,n)cin>>c[0][i];
    R(i,n)cin>>c[1][i];
    vector<vector<int>> dp(1<<n,vector<int>(51,1e9));
    dp[0][0]=0;
    R(B,1<<n){
        int now=0,d[n];
        R(i,n)if(!(B&1<<i))d[i]=now++;
        int cnt=n-now;
        R(i,n){
            int k=abs(i-cnt);
            R(j,c[k%2][i]+1) dp[B|1<<i][c[k%2][i]]=min(dp[B|1<<i][c[k%2][i]],dp[B][j]+d[i]);
        }
    }
    R(i,51)a=min(a,dp[(1<<n)-1][i]);
    cout<<(a==1e9?-1:a);
}