#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <string>
#include <queue>
#include <fstream>
#include <string>
#include <math.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
typedef pair<ll, P> T;

const ll mod = 1000000007;
const ll INF = 100000010000;

ll kai[100010];
ll bit[200010];
ll N, A[20], B[20];
ll ans = INF;


/*ll sum(ll i)
{
	ll s = 0;
	while (i > 0)
	{
		s += bit[i];
		i -= i & -i;
	}
	return s;
}

void add(ll i, ll x)
{
	while (i <= 200005)
	{
		bit[i] += x;
		i += i & -i;
	}
}*/

ll gcd(ll x, ll y)
{
	if (y == 0) return x;
	return gcd(y, x % y);
}

ll pow_mod(ll x, ll y)
{
	if (y == 0) return 1;
	if (y % 2 == 1)
	{
		return x * pow_mod(x, y - 1) % mod;
	}
	else
	{
		ll half = pow_mod(x, y / 2);
		return half * half % mod;
	}
}

ll div_mod(ll x)
{
	return pow_mod(x, mod - 2);
}

ll com(ll x, ll y)
{
	return kai[x] * div_mod(kai[y] * kai[x - y] % mod) % mod;
}

void init()
{
	/*kai[0] = 1;
	for (int i = 1; i <= 10000; i++)
	{
		kai[i] = kai[i - 1] * i % mod;
	}*/
	cin >> N;
	for (int i = 0; i < N; i++)
	{
		cin >> A[i];
	}
	for (int i = 0; i < N; i++)
	{
		cin >> B[i];
	}
}

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

void solve()
{
	for (int i = 0; i < (1 << N); i++)
	{
		bool J = true;
		ll order[20];
		vector<T> vec;
		vector<P> V[55];
		for (int j = 0; j < N; j++)
		{
			if ((i & (1 << j)) == 0)//A
			{
				V[A[j]].push_back(P(j, 0));
				
				//vec.push_back(T(A[j], P(j, 0)));
			}
			else//B
			{
				V[B[j]].push_back(P(j, 1));
				
				//vec.push_back(T(B[j], P(j, 1)));
			}
		}
		/*sort(vec.begin(), vec.end());
		
		for (int j = 0; j < vec.size(); j++)
		{
			V[vec[j].first].push_back(P(vec[j].second.first, vec[j].second.second));
		}*/
		ll t = 0;
		for (int j = 1; j <= 50; j++)
		{
			if (V[j].size() == 0) continue;

			vector<ll> odd, even;
			for (int k = 0; k < V[j].size(); k++)
			{
				if (V[j][k].first % 2 == 1)
				{
					if (V[j][k].second == 1)
					{
						even.push_back(V[j][k].first);
					}
					else
					{
						odd.push_back(V[j][k].first);
					}
				}
				else
				{
					if (V[j][k].second == 1)
					{
						odd.push_back(V[j][k].first);
					}
					else
					{
						even.push_back(V[j][k].first);
					}
				}
			}
			sort(even.begin(), even.end());
			sort(odd.begin(), odd.end());
			if (t % 2 == 0)
			{
				if (even.size() != odd.size() && even.size() != odd.size() + 1)
				{
					J = false;
					break;
				}
				for (int k = 0; k < even.size(); k++)
				{
					order[t + k * 2] = even[k];
				}
				for (int k = 0; k < odd.size(); k++)
				{
					order[t + k * 2 + 1] = odd[k];
				}
			}
			else
			{
				if (even.size() != odd.size() && even.size() + 1 != odd.size())
				{
					J = false;
					break;
				}
				for (int k = 0; k < odd.size(); k++)
				{
					order[t + k * 2] = odd[k];
				}
				for (int k = 0; k < even.size(); k++)
				{
					order[t + k * 2 + 1] = even[k];
				}
			}
			t += V[j].size();
		}
		

		if (!J)
		{
			continue;
		}
		ll cnt = 0;
		for (int j = 0; j < N; j++)
		{
			for (int k = j + 1; k < N; k++)
			{
				if (order[j] > order[k])
				{
					cnt++;
				}
			}
		}
		ans = min(cnt, ans);
	}

}

int main()
{
	init();

	solve();



	output();
	ll N;
	cin >> N;
}


Measured memory_bytes: 256