#include <bits/stdc++.h>
#include <boost/multiprecision/cpp_int.hpp>
using namespace std;
using namespace boost::multiprecision;

# define REP(i,n) for (int i=0;i<(n);++i)
# define rep(i,a,b) for(int i=a;i<(b);++i)
# define all(v) v.begin(),v.end()
# define showVector(v) REP(i,v.size()){cout << (v[i]) << " ";} cout << endl;
template<class T> inline bool chmin(T &a, T b){ if(a > b) { a = b; return true;} return false;}
template<class T> inline bool chmax(T &a, T b){ if(a < b) { a = b; return true;} return false;}
typedef long long int ll;
typedef pair<ll,ll> P_ii;
typedef pair<double,double> P_dd;

template<class T>
vector<T> make_vec(size_t a){
    return vector<T>(a);
}

template<class T, class... Ts>
auto make_vec(size_t a, Ts... ts){
  return vector<decltype(make_vec<T>(ts...))>(a, make_vec<T>(ts...));
}

template<typename T,typename V>
typename enable_if<is_class<T>::value==0>::type
fill_v(T &t,const V &v){t=v;}

template<typename T,typename V>
typename enable_if<is_class<T>::value!=0>::type
fill_v(T &t,const V &v){
  for(auto &e:t) fill_v(e,v);
}

ll gcd(ll a, ll b) {
    if(a < b) swap(a,b);
    
    if(b == 0) return a;
    return gcd(b, a % b);
}

ll lcm(ll a, ll b){
    ll g = gcd(a,b);
    return (a/g)*b;
}

// 素数判定 O(√n)
bool is_prime(int n){
    for(int i = 2; i * i <= n; i++){
        if(n % i == 0) return false;
    }
    return true;
}

// 約数列挙 O(√n)
vector<ll> divisor(ll n){
    vector<ll> res;
    for(ll i = 1; i * i <= n; i++){
        if(n % i == 0){
            res.push_back(i);
            if(i != n / i) res.push_back(n / i);
        }
    }
    return res;
}

vector<pair<ll, ll> > prime_factorize(ll n) {
    vector<pair<ll, ll> > res;
    for (ll p = 2; p * p <= n; ++p) {
        if (n % p != 0) continue;
        ll num = 0;
        while (n % p == 0) { ++num; n /= p; }
        res.push_back(make_pair(p, num));
    }
    if (n != 1) res.push_back(make_pair(n, 1));
    return res;
}

// auto mod int
// https://youtu.be/L8grWxBlIZ4?t=9858
// https://youtu.be/ERZuLAxZffQ?t=4807 : optimize
// https://youtu.be/8uowVvQ_-Mo?t=1329 : division
const int mod = 1000000007;
struct mint {
  ll x; // typedef long long ll;
  mint(ll x=0):x(x%mod){}
  mint& operator+=(const mint a) {
    if ((x += a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator-=(const mint a) {
    if ((x += mod-a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator*=(const mint a) {
    (x *= a.x) %= mod;
    return *this;
  }
  mint operator+(const mint a) const {
    mint res(*this);
    return res+=a;
  }
  mint operator-(const mint a) const {
    mint res(*this);
    return res-=a;
  }
  mint operator*(const mint a) const {
    mint res(*this);
    return res*=a;
  }
  mint pow(ll t) const {
    if (!t) return 1;
    mint a = pow(t>>1);
    a *= a;
    if (t&1) a *= *this;
    return a;
  }
 
  // for prime mod
  mint inv() const {
    return pow(mod-2);
  }
  mint& operator/=(const mint a) {
    return (*this) *= a.inv();
  }
  mint operator/(const mint a) const {
    mint res(*this);
    return res/=a;
  }
};

const int MOD = 1000000007;
const int inf=1e9+7;
const ll longinf=1LL<<60 ;

void addM(ll &a, ll b) {
    a += b;
    if (a >= MOD) a -= MOD;
}

void mulM(ll &a, ll b) {
    a = ((a%MOD)*(b%MOD))%MOD ;
}

ll powM(ll a,ll b) {
    ll ret = 1;
    ll tmp = a;
    while(b>0) {
        if((b&1)==1) ret = (ret * tmp) % MOD;
        tmp = (tmp * tmp) % MOD;
        b = b >> 1;
    }
    return ret;
}

// mod. m での a の逆元 a^{-1} を計算する
ll modinv(ll a, ll m) {
    ll b = m, u = 1, v = 0;
    while (b) {
        ll t = a / b;
        a -= t * b; swap(a, b);
        u -= t * v; swap(u, v);
    }
    u %= m;
    if (u < 0) u += m;
    return u;
}

// ラングレンス圧縮
vector<pair<char, int>> rang_com(string s){
  vector<pair<char, int>> ret;
  string t = s;
  t.erase(unique(all(t)), t.end());
  int now = 0;
  int pre = 0;
  for(auto ct : t){
    while(now < s.size() && s[now] == ct) now++;
    if(ret.size() == 0){
      ret.push_back({ct, now});
    } else {
      ret.push_back({ct, now - pre});
    }
    pre = now;
  }
  return ret;
}

template<typename T>
struct SegmentTree{
    struct Node{
        T val;
        Node *lch,*rch;
        Node(T val):val(val),lch(nullptr),rch(nullptr){}
    };

    Node *root;
    ll sz;
    T id;

    T f(T x,T y){
        return x + y; // 計算式
    }

    T g(T x,T y){
        return x; // 上書き
        // return x + y; // 加算
    }

    T val(Node* t){return t ? t->val : id;}

    SegmentTree(ll sz_,T id_=0):root(nullptr),id(id_){
        sz=1;
        while(sz<sz_)sz*=2;
    }

    void erase(Node* t){
        if(t->lch)erase(t->lch);
        if(t->rch)erase(t->rch);
        delete t;
    }

    void erase(){
        erase(root);
    }

    Node* update(Node* t,ll k, ll l, ll r, T x){
        //assert(l<=k&&k<r);
        if(!t)t=new Node(id);
        if(r-l==1){
            t->val=g(x,t->val);
            return t;
        }
        if(k<(l+r)/2)t->lch=update(t->lch,k, l, (l+r)>>1, x);
        else t->rch=update(t->rch,k, (l+r)>>1, r, x);
        t->val=f(val(t->lch), val(t->rch));
        return t;
    }

    T get(Node* t, ll a,ll b,ll l, ll r){
        if(!t)return id;
        if(b<=l||r<=a)return id;
        if(a<=l&&r<=b)return t->val;
        T lx=get(t->lch, a, b, l, (l+r)>>1);
        T rx=get(t->rch, a, b, (l+r)>>1, r);
        return f(lx,rx);
    }

    void update(ll k,T x){
        root = update(root, k, 0, sz, x);
    }

    // [a, b)
    T get(ll a, ll b){
        return get(root, a, b, 0, sz);
    }
};

int main(void) {
  cin.tie(0);
  ios::sync_with_stdio(false);  

  int N;
  cin >> N;

  vector<ll> a(N), b(N);
  REP(i, N) cin >> a[i];
  REP(i, N) cin >> b[i];

  ll res = longinf;
  REP(i, (1 << N)){
    int cnt = __builtin_popcount(i);
    if(cnt != N / 2) continue;

    vector<P_ii> c, d;  
    REP(j, N){      
      if((i >> j) & 1){
        int val = (j % 2 == 1 ? a[j] : b[j]);
        d.push_back({val, j});
      } else {
        int val = (j % 2 == 0 ? a[j] : b[j]);        
        c.push_back({val, j});
      }
    }

    sort(all(c));
    sort(all(d));

    SegmentTree<int> sg(N, 0);

    int now = 0;
    ll ans = 0;
    bool flg = true;
    REP(k, N){
      int j = k / 2;
      int val = (k % 2 == 0 ? c[j] : d[j]).first;
      int pos = (k % 2 == 0 ? c[j] : d[j]).second;
      if(now > val){
        flg = false;
        break;
      }
      ans += k - sg.get(0, pos);
      sg.update(pos, 1);
      now = val;
    }
    if(!flg) continue;

    chmin(res, ans);
  }
  if(res == longinf) res = -1;
  cout << res << endl;

  return 0;
}

Measured memory_bytes: 58368