/*
    Author:zeke
    
    pass System Test!
    GET AC!!
*/
#include <iostream>
#include <queue>
#include <vector>
#include <iostream>
#include <vector>
#include <string>
#include <cassert>
#include <algorithm>
#include <functional>
#include <cmath>
#include <queue>
#include <set>
#include <stack>
#include <deque>
#include <map>
#include <iomanip>
#include <utility>
#include <stack>
#include <bitset>
using ll = long long;
using ld = long double;
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(), (x).end()
#define rep3(var, min, max) for (ll(var) = (min); (var) < (max); ++(var))
#define repi3(var, min, max) for (ll(var) = (max)-1; (var) + 1 > (min); --(var))
#define Mp(a, b) make_pair((a), (b))
#define F first
#define S second
#define Icin(s) \
    ll(s);      \
    cin >> (s);
#define Scin(s) \
    ll(s);      \
    cin >> (s);
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;
}
typedef pair<ll, ll> P;
typedef vector<ll> V;
typedef vector<V> VV;
typedef vector<P> VP;
ll mod = 1e9 + 7;
ll MOD = 1e9 + 7;
ll INF = 1e18;
struct BIT
{
private:
    vector<int> bit;
    int N;

public:
    BIT(int size)
    {
        N = size;
        bit.resize(N + 1);
    }

    // 一点更新です
    void add(int a, int w)
    {
        for (int x = a; x <= N; x += x & -x)
            bit[x] += w;
    }

    // 1~Nまでの和を求める。
    int sum(int a)
    {
        int ret = 0;
        for (int x = a; x > 0; x -= x & -x)
            ret += bit[x];
        return ret;
    }
};

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll n;
    cin >> n;
    V vec1(n);
    rep(i, n) cin >> vec1[i];
    V vec2(n);
    rep(i, n) cin >> vec2[i];
    ll res = 1e18;
    rep(k, (1 << n))
    {
        VP temp;
        ll count = 0;
        rep(j, n)
        {
            if (k & (1 << j))
            {
                temp.push_back({vec1[j], 0});
            }
            else
            {
                temp.push_back({vec2[j], 1});
            }
        }
        rep(i, n)
        {
            rep(j, n - 1)
            {
                if (temp[j + 1].first < temp[j].first)
                {
                    swap(temp[j + 1], temp[j]);
                    temp[j + 1].second = 1 - temp[j + 1].second;
                    temp[j].second = 1 - temp[j].second;
                    count++;
                }
            }
        }
        rep(i, n - 1)
        {
            if (temp[i].first == temp[i + 1].first && temp[i].second && temp[i + 1].second)
            {
                temp[i].second = 0;
                temp[i + 1].second = 0;
                count++;
            }
            if (i<n-2&&temp[i].first == temp[i + 2].first && temp[i].second && !temp[i + 2].second)
            {
                temp[i].second = 0;
                temp[i + 2].second = 1;
                count += 2;
            }
        }
        bool h=true;
        rep(i,n){
            if(temp[i].second){
                h = false;
                break;
            }
        }
        if(h){
            chmin(res, count);
        }
    }
    if(res==1e18){
        cout << -1 << endl;
        return 0;
    }
    cout << res << endl;
}


Measured memory_bytes: 256