//#include "bits/stdc++.h"

#define _USE_MATH_DEFINES
#include<cstdio>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <deque>
#include <algorithm>
#include <functional>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#include <iterator>
#include<iomanip>
#include<unordered_set>
#include<bitset>
#include<complex>

using namespace std;

#define rep(i,a,b) for(int i=(a), i##_len=(b);i<i##_len;i++)
#define rrep(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define all(c) begin(c),end(c)

#define int ll
#define SZ(x) ((int)(x).size())
#define pb push_back
#define mp make_pair

//typedef unsigned long long ull;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<ll, int> pli;
typedef pair<double, double> pdd;
typedef vector< vector<int> > mat;

template<class T> bool chmax(T &a, const T &b) { if (a < b) { a = b; return true; } return false; }
template<class T> bool chmin(T &a, const T &b) { if (b < a) { a = b; return true; } return false; }

const int INF = sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f;
const int MOD =  (int)1e9 + 7;
const double EPS = 1e-9;

struct BIT
{
	//[0,mn]
	vector<int> node;
	int mn;

	BIT(int mn)
	{
		this->mn = mn;
		node.resize(mn + 1, 0);
	}

	void add(int i, int x)
	{
		while (i <= mn)
		{
			node[i] += x;
			i += (i&-i);
		}
	}

	int sum(int i)
	{
		int res = 0;
		while (i > 0)
		{
			res += node[i];
			i -= (i&-i);
		}
		return res;
	}
};

int N;
int X[20], Y[20];
int B[20];
vector<vector<int>> vs;

void func(int idx, int cnt)
{
	if (N - idx + cnt < N / 2)return;
	if (idx == N)
	{
		vector<int> v;
		rep(i, 0, N)
		{
			v.push_back(B[i]);
		}
		vs.push_back(v);
	}
	else
	{
		if (N - cnt - cnt > 1)
		{
			B[idx] = 1;
			func(idx + 1, cnt + 1);
		}
		B[idx] = 0;
		func(idx + 1, cnt);
	}
}

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

	cin >> N;
	rep(i, 0, N)
	{
		cin >> X[i];
	}
	rep(i, 0, N)
	{
		cin >> Y[i];
	}

	if (N == 1)
	{
		cout << 0 << endl;
		return 0;
	}

	func(0, 0);

	int ans = INF;

	for (const auto& v : vs)
	{
		vector<pii> odd, eve;
		rep(i, 0, N)
		{
			if (v[i] == 1)
			{
				if (i % 2 == 0)
				{
					odd.push_back(mp(Y[i], i));
				}
				else
				{
					odd.push_back(mp(X[i], i));
				}
			}
			else
			{
				if (i % 2 == 0)
				{
					eve.push_back(mp(X[i], i));
				}
				else
				{
					eve.push_back(mp(Y[i], i));
				}
			}
		}
		sort(all(odd));
		sort(all(eve));

		bool ok = true;
		rep(i, 0, N - 1)
		{
			if (i % 2 == 0)
			{
				if (eve[i / 2].first > odd[(i + 1) / 2].first)
				{
					ok = false;
				}
			}
			else
			{
				if (odd[i / 2].first > eve[(i + 1) / 2].first)
				{
					ok = false;
				}
			}
		}
		if (!ok)continue;
		int NP[20];
		rep(i, 0, SZ(eve))
		{
			NP[2 * i] = eve[i].second;
		}
		rep(i, 0, SZ(odd))
		{
			NP[2 * i + 1] = odd[i].second;
		}
		int res = 0;
		BIT bit(20);

		rep(i, 0, N)
		{
			res += NP[i] + bit.sum(N) - bit.sum(NP[i] + 1) - i;
			bit.add(NP[i] + 1, 1);
		}
		chmin(ans, res);
	}

	if (ans == INF)
	{
		cout << -1 << endl;
	}
	else
	{
		cout << ans << endl;
	}

	/*int NP[20];
	cin >> N;
	rep(i, 0, N)cin >> NP[i];
	int res = 0;
	BIT bit(20);

	rep(i, 0, N)
	{
		res += NP[i] + bit.sum(N)-bit.sum(NP[i] + 1) - i;
		bit.add(NP[i] + 1, 1);
	}
	cout << res << endl;*/

	return 0;
}

Measured memory_bytes: 9140