#include <iostream>
#include <map>
#include <set>
#include <cmath>
#include <algorithm>
#include <vector>
#include <string>
#include <fstream>
#include <bitset>
#include <queue>
#include <stack>
#include <deque>
#include <complex>
#include <iomanip>
#include <stdio.h>
#include <string.h>
#include <random>
#include <functional>

using std::cin;
using std::cout;
using std::cerr;
using std::endl;

using std::map;
using std::set;
using std::bitset;
using std::vector;
using std::string;
using std::multimap;
using std::multiset;
using std::deque;
using std::queue;
using std::stack;
using std::pair;
using std::iterator;

using std::sort;
using std::stable_sort;
using std::reverse;
using std::max_element;
using std::min_element;
using std::unique;
using std::ios_base;
using std::swap;
using std::fill;

using std::setprecision;
using std::fixed;

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<long long> vl;
typedef string S;

ll min(ll a, ll b) {return a < b ? a : b;}
ll min(int a, ll b) {return a < b ? a : b;}
ll min(ll a, int b) {return a < b ? a : b;}
ll min(int a, int b) {return a < b ? a : b;}

ll max(ll a, ll b) {return a > b ? a : b;}
ll max(int a, ll b) {return a > b ? a : b;}
ll max(ll a, int b) {return a > b ? a : b;}
ll max(int a, int b) {return a > b ? a : b;}

namespace MySpace{

};

#define F(i, n) for (int (i) = 0; (i) != (n); (i)++)
#define fi first
#define se second
#define re return
#define all(x) (x).begin(), (x).end()
#define int long long

int n;
int a[20], b[20];

signed main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    cin >> n;
    for (int i = 0; i < n; i++)
    {
        cin >> a[i];
    }
    for (int i = 0; i < n; i++)
    {
        cin >> b[i];
    }
    int ans = 1e9;
    int bi = 0;
    for (int i = 0; i < n; i++) if (i % 2 == 0) bi++;
    vector<int> q;
    for (int i = 0; i < n - bi; i++) q.push_back(0);
    for (int i = 0; i < bi; i++) q.push_back(1);
    while (1)
    {
        vector<pii> on0, on1;
        for (int i = 0; i < n; i++)
        {
            if (i % 2 == 0 && q[i]) on0.push_back({a[i], i});
            if (i % 2 == 1 && q[i]) on0.push_back({b[i], i});
            if (i % 2 == 1 && !q[i]) on1.push_back({a[i], i});
            if (i % 2 == 0 && !q[i]) on1.push_back({b[i], i});
        }
        sort(all(on1));
        sort(all(on0));
        int t = 1;
        vector<pii> c;
        for (int i = 0; i < on1.size(); i++) c.push_back(on0[i]), c.push_back(on1[i]);
        if (on0.size() > on1.size()) c.push_back(on0[on0.size() - 1]);
        for (int i = 0; i + 1 < c.size(); i++) if (c[i].first > c[i + 1].first) t = 0;
        if (t)
        {
            int r = 0;
            for (int i = 0; i < n; i++)
            {
                for (int j = i; j < n; j++)
                {
                    if (c[j].second == i)
                    {
                        for (int k = j - 1; k >= i; k--)
                        {
                            swap(c[k], c[k + 1]);
                            r++;
                        }
                        break;
                    }
                }
            }
            ans = min(ans, r);
        }
        if (!next_permutation(all(q))) break;
    }
    if (ans == 1e9)
    {
        cout << -1;
    }
    else
    {
        cout << ans;
    }
}


Measured memory_bytes: 256