#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < (n); ++i)
#define repA(i, a, n) for(int  i = a; i <= (n); ++i)
#define all(x) x.begin(), x.end()
#define sz(x) (int) (x).size()
#define fill(a) memset(a, 0, sizeof(a))
#define fst first
#define snd second
#define mp make_pair
#define pb push_back
#define endl '\n'
#define init(n) int n;cin>>n;int a[n];rep(i,n)cin>>a[i];
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<double> vd;
typedef vector<long long int> vll;
typedef vector<pii> vii;

int main() {
    cin.sync_with_stdio(0); cin.tie(0); 
    cin.exceptions(cin.failbit);
    int T=1;
    // cin>>T;
    while(T--){
        int n;cin>>n;
        int a[n],b[n];
        rep(i,n)cin>>a[i];
        rep(i,n)cin>>b[i];
        int total=(1<<(n))-1;
        int ans=INT_MAX;
        for(int mask=0;mask<=total;mask++){
            pair<int,int> arr[n];
            for(int j=0;j<n;j++){
                arr[j].fst=a[j];
                if((mask&(1<<j))!=0){
                    arr[j].fst=b[j];
                }
                arr[j].snd=j;
                // cout<<arr[j].fst<<endl;
            }
            int temp=0;
            for(int i=0;i<n;i++){
                for(int j=i+1;j<n;j++){
                    if(arr[i].fst>arr[j].fst)temp++;
                }
            }
            sort(arr,arr+n);
            // rep(i,n){
            //     cout<<arr[i].fst<<" "<<abs(arr[i].snd-i)<<endl;
            // }
            int flag=1;
            int last=-1;
            for(int i=n-1;i>=0;i--){
                if(((abs(arr[i].snd-i))%2)==0){
                    if((mask&(1<<(arr[i].snd)))!=0){
                        if(last!=-1){
                            if(arr[last].fst==arr[i].fst){
                                int e=(last-i)-1;
                                if(e%2==0){
                                    flag=1;
                                    temp=temp+(e+1);
                                }
                                else{
                                    break;
                                }
                            }   
                            else{
                                flag=0;
                                break;
                            }
                            last=-1;continue;
                        }
                        last=i;
                        flag=0;
                    }
                }
                else{
                    if((mask&(1<<(arr[i].snd)))==0){
                        if(last!=-1){
                            // cout<<last<<endl;
                            if(arr[last].fst==arr[i].fst){
                                int e=(last-i)-1;
                                if(e%2==0){
                                    flag=1;
                                    temp=temp+(e+1);
                                }
                                else{
                                    flag=0;
                                    break;
                                }
                            }   
                            else{
                                flag=0;
                                break;
                            }
                            last=-1;continue;
                        }
                        last=i;
                        flag=0;
                    }
                }
            }
            if(flag){
                ans=min(ans,temp);
            }
        }
        if(ans==INT_MAX)ans=-1;
        cout<<ans;
    }
    return 0;   
}


Measured memory_bytes: 256