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

typedef unsigned long ul;
typedef unsigned long long ull;
typedef long long ll;
typedef vector<ll> vint;
typedef vector< vector<ll> > vvint;
typedef vector< vector< vector<ll> > > vvvint;
typedef vector<string> vstring;
typedef vector< vector<string> > vvstring;
typedef vector<char> vchar;
typedef vector< vector<char> > vvchar;
typedef vector<long double> vdouble;
typedef vector< vector<long double> > vvdouble;
typedef vector< vector< vector<long double> > > vvvdouble;
typedef pair<ll,ll> pint;
typedef vector<pint> vpint;
typedef vector<bool> vbool;

#define rep(i,n) for(ll i=0;i<n;i++)
#define repf(i,f,n) for(ll i=f;i<n;i++)
#define repr(i,n) for(ll i=n-1;i>=0;i--)
#define mp make_pair
#define mt make_tuple
#define pb push_back
#define pf push_front
#define fi first
#define se second
#define ALL(obj) (obj).begin(), (obj).end()
// #define LLONG_MAX 9223372036854775806
#define MOD 1000000007
const double PI=3.14159265358979323846;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
template<typename T> T Ceil(T a, T b){return (a+b-1)/b;}

int dy[]={0, 0, 1, -1, 1, -1, -1, 1};
int dx[]={1, -1, 0, 0, 1, 1, -1, -1};

void printv(vint &v){
    for(auto e:v) cout<<e<<" ";
        cout<<endl;
    }
template< typename T >
struct BinaryIndexedTree {
  vector< T > data;

  BinaryIndexedTree(int sz) {
    data.assign(++sz, 0);
  }

  T sum(int k) {
    T ret = 0;
    for(++k; k > 0; k -= k & -k) ret += data[k];
    return (ret);
  }

  void add(int k, T x) {
    for(++k; k < data.size(); k += k & -k) data[k] += x;
  }
};

int main() {
    cout<<fixed<<setprecision(10);

    ll n; cin>>n;
    vint a(n),b(n);
    rep(i,n)cin>>a[i];
    rep(i,n)cin>>b[i];

    ll ans = LLONG_MAX;
    rep(i,(1ll<<n)){
        // cout<<i<<endl;
        vpint even,odd;
        rep(j,n){
            if((i>>j)&1){
                // omote
                // puts("omote");
                if(j%2==0) even.emplace_back(a[j], j);
                else odd.emplace_back(a[j], j);
            }else{
                // ura
                // puts("ura");
                if((j+1)%2==0) even.emplace_back(b[j], j);
                else odd.emplace_back(b[j], j);
            }
        }
        if(odd.size() != n/2) continue;
        sort(ALL(even));
        sort(ALL(odd));
        // for(auto p:even) cout<<"("<<p.first<<", "<<p.second<<") ";
        // cout<<endl;
        // for(auto p:odd) cout<<"("<<p.first<<", "<<p.second<<") ";
        // cout<<endl;


        vpint tot(n);
        rep(i,even.size()){
            tot[2*i] = even[i];
        }
        rep(i,odd.size()){
            tot[2*i+1] = odd[i];
        }

        bool ok = true;
        rep(i,n-1){
            if(tot[i].first > tot[i+1].first){
                ok = false;
                break;
            }
        }
        if(!ok) continue;
        // for(auto p:tot) cout<<"("<<p.first<<", "<<p.second<<") ";
        // cout<<endl;

        BinaryIndexedTree<ll> bit(n+1);

        ll tmp = 0;
        rep(i,n){
            auto p = tot[i];
            tmp += bit.sum(n) - bit.sum(p.second+1);
            bit.add(p.second+1, 1);
        }
        chmin(ans, tmp);
    }


    if(ans == LLONG_MAX) cout<<-1<<endl;
    else cout<<ans<<endl;


    return 0;

}

Measured memory_bytes: 256