#include <bits/stdc++.h>

using namespace std;
#define _for(i,j,N) for(int i = (j);i < (N);i++)
#define _rep(i,j,N) for(int i = (j);i <= (N);i++)
#define _dec(i,N,j) for(int i = (N-1);i >= (j);i--)
#define _rec(i,N,j) for(int i = (N);i >=(j);i--)
#define ALL(x) x.begin(),x.end()
#define MEM(a,n) memset(a,n,sizeof(a))
#define fst first
#define scd second
#define PB push_back
#define MP make_pair

typedef long long LL;
typedef long double LD;
typedef pair<int,int> pii;
typedef pair<LL,LL> pll;

int get_int(){int x;scanf("%d",&x);return x;}
LL get_ll(){LL x;scanf("%lld",&x);return x;}
double get_db(){double x;scanf("%lf",&x);return x;}

template<typename T> int chmin(T &a,T b){if(a > b){a = b;return 1;}else return 0;}
template<typename T> int chmax(T &a,T b){if(a < b){a = b;return 1;}else return 0;}
template<typename T>
ostream& operator<<(ostream& os,const vector<T>& v) {_for(i,0,v.size()) os << v[i] << " ";return os;}
template<typename T>
ostream& operator<<(ostream& os,const set<T>& v){for(auto a:v) os << a <<" ";return os;}
template<typename T1,typename T2>
ostream& operator<<(ostream& os,const pair<T1,T2>& v){os << v.fst <<" "<<v.scd << " ";return os;}
template<typename T1,typename T2>
ostream& operator<<(ostream& os,const map<T1,T2>& v){for(auto a:v) cout << a << endl;return os;}

static const int dx[8] = { -1,  0, 1, 0,  1, -1,  1, -1};
static const int dy[8] = {0,  1, 0,  -1,  1, -1, -1,  1};
const double pi  = acos(-1.0);
const double eps = 1e-8;
const LL  INF  = 0x3f3f3f3f3f3f3f3f;
const int inf  = 0x3f3f3f3f;

const int maxn = 20;
int used[20];
int us[20];

int up[20];
int down[20];

int N;
int ans = 1e9;

bool OK(){
    pii u[15];int p1 = 0;
    pii d[15];int p2 = 0;

    _rep(i,1,N){
        if(used[i] == 0) {
            u[p1++] = MP(up[i],i);
        }
        else {
            d[p2++] = MP(down[i],i);
        }
    }

    sort(u , u + p1);
    sort(d , d + p2);

    /*
     _rep(i,0,p1-1){
        cout << u[i] << " ";
    }
    cout << endl;
     _rep(i,0,p2-1){
        cout << d[i] << " ";
    }
    cout << endl;
    */

    int a = u[0].first;
    int p3 = 1;
    int p4 = 0;
    int k = 2;
    us[1] = u[0].second;

    while(p3 < p1 || p4 < p2){
        //printf("%d ",a);
        if(d[p4].first < a) return false;
        us[k++] = d[p4].second;
        a = d[p4++].first;

        if(p3 == p1 && p2 == p4) break;

        if(u[p3].first < a) return false;
        us[k++] = u[p3].second;

        a = u[p3++].first;
    }
    //printf("\n");
    /*
    _rep(i,1,N){
        cout << aa[i].first << " ";
    }
    cout << endl;
    */
    return true;
}

int counts(){
    int ret = 0;
    _rep(i,1,N){
        _rep(j,i+1,N){
            if(us[i] > us[j]) ret++;
        }
    }
    return ret;
}

void searching(int a,int b,int d){
    if( a == 0 && b == 0){
        if(OK()){
            ans = min(ans,counts());
        }
        return;
    }
    if(a > 0){
        used[d] = 0;
        searching(a-1,b,d+1);
        used[d] = -1;
    }
    if(b > 0){
        used[d] = 1;
        searching(a,b-1,d+1);
        used[d] = -1;
    }
}



int main()
{

    cin >> N;
    _rep(i,1,N){
        int a;
        cin >> a;
        if(i % 2) up[i] = a;
        else down[i] = a;
    }
    _rep(i,1,N){
        int b;
        cin >> b;
        if(i%2) down[i] = b;
        else up[i] = b;
    }

    MEM(used,-1);
    searching((N+1)/2,N/2,1);

    if(ans == 1e9) printf("-1\n");
    else printf("%d\n",ans);

    return 0;
}


Measured memory_bytes: 256