#include <bits/stdc++.h>
using namespace std;
using ll = long long;
template<class T,class U> using P = pair<T,U>;
template<class T> using vec = vector<T>;
template<class T> using vvec = vector<vec<T>>;

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N;
    cin >> N;
    vec<int> A(N),B(N);
    for(int i=0;i<N;i++) cin >> A[i];
    for(int i=0;i<N;i++) cin >> B[i];
    int inf = 1e9;
    vvec<int> dp(1<<N,vec<int>(51,inf));
    dp[0][0] = 0;
    for(int S=0;S<(1<<N);S++){
        for(int j=0;j<N;j++) if(!(S&(1<<j))){
            int n = __builtin_popcount(S);
            int ne = (abs(n-j)%2? B[j]:A[j]);
            int T = S^(1<<j);
            int now = j;
            int cost = 0;
            for(int k=j+1;k<N;k++) if(S&(1<<k)) now++;
            if(now>=n) cost = now-n;
            int c = 0;
            for(int k=N-1;k>=0;k--){
                if(S&(1<<k)) c++;
                else if(k!=j && k+c<n) cost++;
            }
            for(int k=0;k<=50;k++) if(k<=ne && dp[S][k]!=inf){
                dp[T][ne] = min(dp[T][ne],dp[S][k]+cost);
            }
        }
    }
    int ans = inf;
    for(int k=0;k<=50;k++) ans = min(ans,dp[(1<<N)-1][k]);
    cout << (ans==inf? -1:ans) << endl;
}