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

#define REP(i,m,n) for(int i=(m); i<(int)(n); i++)
#define RREP(i,m,n) for(int i=(int)((n)-1); i>=m; i--)
#define rep(i,n) REP(i,0,n)
#define rrep(i,n) RREP(i,0,n)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define fi first
#define se second
#define debug(...) {cerr<<"[L"<<__LINE__<<"] "; _debug(__VA_ARGS__);}

template<typename T>
string join(const vector<T>&v, string del=", "){ stringstream s;
    for(auto x : v) s << del << x; return s.str().substr(del.size());
}
template<typename T>
ostream& operator<<(ostream& o, const vector<T>&v){
    if(v.size()) o << "[" << join(v) << "]"; return o;
}
template<typename T>
ostream& operator<<(ostream& o, const vector<vector<T> >&vv){
    int l = vv.size();
    if(l){ o<<endl; rep(i,l) o << (i==0 ? "[ " : ",\n  " ) << vv[i] << (i==l-1 ? " ]" : ""); }
    return o;
}
template<typename T1, typename T2>
ostream& operator<<(ostream& o, const pair<T1, T2>& p){
    return o << "(" << p.first << ", " << p.second << ")";
}
inline void _debug(){cerr<<endl;}
template<class First, class... Rest>
void _debug(const First& first, const Rest&... rest){cerr<<first<<" ";_debug(rest...);}

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<vl> vvl;

const double PI = (1*acos(0.0));
const double EPS = 1e-9;
const int INF = 0x3f3f3f3f;
const ll INFL = 0x3f3f3f3f3f3f3f3fLL;
const ll mod = 1e9 + 7;

inline void finput(string filename) {
    freopen(filename.c_str(), "r", stdin);
}

template<typename T>
struct BIT{
    int n;
    vector<T> dat;
    BIT(int n) : n(n), dat(n+1,0){}
    void add(int x, T val){
        for(int i = x+1; i <= n; i += (i & -i)) dat[i] += val;
    }
    T sum(int x){
        T ret = 0;
        for(int i = x+1; i > 0; i -= (i & -i)) ret += dat[i];
        return ret;
    }
    T sum(int a, int b){
        return sum(b) - sum(a-1);
    }
};

void solve(){
    int n; cin >> n;
    vi a(n),b(n);
    rep(i,n) cin >> a[i];
    rep(i,n) cin >> b[i];

    int ans = INF;
    rep(bit,1<<n){
        if(__builtin_popcountll(bit) & 1) continue;
        vector<pii> odd, even;
        rep(i,n){
            int x = (bit>>i & 1) ? b[i] : a[i];
            if(bit>>i&1 ^ (i+1)&1){
                odd.emplace_back(x, i);
            }else{
                even.emplace_back(x, i);
            }
        }

        if(odd.size() == (n+1)/2){
            bool ok = true;
            sort(all(odd));
            sort(all(even));
            auto bit = BIT<int>(n+1);
            int pre = 0, res = 0;
            rep(i,n){
                vector<pii> v = (i % 2 == 0) ? odd : even;
                if(v[i/2].fi < pre) ok = false;
                pre = v[i/2].fi;
                res += bit.sum(v[i/2].se+1,n);
                bit.add(v[i/2].se, 1);
            }
            if(ok) ans = min(ans, res);
        }
    }
    if(ans == INF) cout << -1 << endl;
    else cout << ans << endl;
}

void solve2(){
    int n; cin >> n;
    vi a(n),b(n);
    rep(i,n) cin >> a[i];
    rep(i,n) cin >> b[i];

    vvi dp(1<<n, vi(n, INF));
    rep(i,n) dp[1<<i][i] = 0;
    REP(bit,1,1<<n){
        rep(i,n){
            if((bit>>i) & 1 == 0) continue;
            int pos = __builtin_popcountll(bit) - 1;
            int x = ((pos-i) % 2 == 0) ? a[i] : b[i];
            int inv_num = 0;
            rrep(j,n){
                if((bit>>j) & 1 == 1){ inv_num++; continue; }
                int y = ((pos+1-j) % 2 == 0) ? a[j] : b[j];
                if(x <= y){
                    int next = bit|(1<<j);
                    dp[next][j] = min(dp[next][j], dp[bit][i] + inv_num);
                }
            }
        }
    }
    int ans = *min_element(all(dp[(1<<n)-1]));
    if(ans == INF) cout << -1 << endl;
    else cout << ans << endl;
}

int main(){
    ios_base::sync_with_stdio(0);
    // finput("./input");
    solve2();
    return 0;
}

Measured memory_bytes: 29928