#include <iostream>
#include <string>
#include <vector>
#include <algorithm> // sort
#include <map> // pair
#include <queue>
#include<iomanip>
#include <cmath>
#include <set>
#include <unordered_set>

#define ABS(x) ((x)>0?(x):-(x))
#define MIN(x,y) ((x)>(y)?(y):(x))
#define MAX(x,y) ((x)<(y)?(y):(x))

#define SIZE_OF_ARRAY(array) (sizeof(array)/sizeof(array[0]))

#define INF 1000000000

using namespace std;
typedef long long ll;

ll newton(long long int a, long long int  b)
{
	if(a==b)
		return a;
	while(a != 0 && b != 0)
	{
		if(a > b)
		{
			b += a;
			a = b-a;
			b -= a;
		}
		b %= a;
	}
	return a;
}

struct UnionFind {
	vector<int> p;
	UnionFind(int N):p(N)
	{
		for(int i=0; i< N; i++)
		{
			p[i] = i;
		}
	}
	int root(int x)
	{
		if(p[x] == x)
			return x;
		return p[x] = root(p[x]);
	}
	void unite(int x, int y)
	{
		int rx = root(x);
		int ry = root(y);
		if(rx == ry) return;
		p[rx] = ry;
	}
	bool issame(int x, int y)
	{
		int rx = root(x);
		int ry = root(y);
		return rx == ry;
	}
};

//大きな数に対する割り算をするとき、MODを指定することで掛け算の値に変換できる

ll div2mul_calc(ll a, ll b, ll m)
{
	if (b == 0) {
        return 1;
    } else if (b % 2 == 0) {
        ll d = div2mul_calc(a, b / 2, m);
        return (d * d) % m;
    } else {
        return (a * div2mul_calc(a, b - 1, m)) % m;
    }
}
ll div2mul(ll n, ll mod)
{
	return div2mul_calc(n, mod-2, mod);
}

ll twoRow(ll a, ll b, ll mod)
{
	ll ret = 1;
	for(ll i = 1 ;i <= a+b;++i)
	{
		ret *= i;
		ret %= mod;
	}
	for(ll i = 1 ;i <= a;++i)
	{
		ret *= div2mul(i,mod);
		ret %= mod;
	}
	for(ll i = 1 ;i <= b;++i)
	{
		ret *= div2mul(i,mod);
		ret %= mod;
	}
	return ret;
}

struct edge {
    int from; //出発点
    int to;   //到達点
    int cost; //移動コスト
};

vector< ll > divisor(ll n) {
  vector< ll > ret;
  for(ll i = 1; i * i <= n; i++) {
    if(n % i == 0) {
      ret.push_back(i);
      if(i * i != n) ret.push_back(n / i);
    }
  }
  sort(ret.begin(), ret.end());
  return (ret);
}
/*
小数の桁数を指定する
	cout << setprecision(8)<< mp[0]-mx << endl;
*/

int main()
{
	ll i,j,k,a,b;//,ans=0;
	char c;
	ll endi;
	ll N,M,T, X,Y;
	ll tm[100010] = {0};
	ll A[2][32];
	cin >> N;
	for(i=0;i<N;++i)
		cin >> A[0][i];
	for(i=0;i<N;++i)
		cin >> A[1][i];
	endi = 1 << N;
	int ans = 1000000;

	pair<int,int> v;
	int col[2][32];
	int col_ind[2];
	int col_mx[2];
	col_mx[0] = (N+1)/2;
	col_mx[1] = (N)/2;
	for(i=0;i<endi;++i)
	{
		//cout << " #### "<< i << endl;
		j = 1;
		a = 0;
		for(k = 0;k < N;++k)
		{
			a += !!(j&i);
			j <<= 1;
		}
		if(a&1)
			continue;
		//cout << "個数OK" << endl;
		j = 1;
		a = 0;
		b = 1;
		col_ind[0] = 0;
		col_ind[1] = 0;
		for(k = 0;k < N;++k)
		{
			if(i&j)
			{
				a = (k+1)&1;
				col[a][col_ind[a]++] = A[1][k]*20+k;
				if(col_ind[a] > col_mx[a])
				{
					b = 0;
					break;
				}
			}
			else
			{
				a = k&1;
				col[a][col_ind[a]++] = A[0][k]*20+k;
				if(col_ind[a] > col_mx[a])
				{
					b = 0;
					break;
				}
			}
			j <<= 1;
		}
		if(!b)
			continue;
		//cout << "振り分けOK" << endl;
		stable_sort(col[0],&col[0][col_ind[0]]);
		stable_sort(col[1],&col[1][col_ind[1]]);
		j = 0;
		b = 1;
		for(k=0;k<N;++k)
		{
			if(k&1)
			{
				if(col[1][k/2]/20 >= j)
				{
					j = col[1][k/2]/20;
					tm[k] = col[1][k/2]%20;
				}
				else
				{
					b = 0;
					break;
				}
			}
			else
			{
				if(col[0][k/2]/20 >= j)
				{
					j = col[0][k/2]/20;
					tm[k] = col[0][k/2]%20;
				}
				else
				{
					b = 0;
					break;
				}
			}
		}
		if(!b)
			continue;
		/*
		cout << "Can row" << endl;
		for(a=0;a<N;++a)
		{
			cout << tm[a] << " ";
		}
		cout << endl;*/
		k = 0;
		for(a=0;a<N-1;++a)
		{
			for(j=0;j<N-1-a;++j)
			{
				if(tm[j] > tm[j+1])
				{
					tm[j] += tm[j+1];
					tm[j+1] = tm[j]-tm[j+1];
					tm[j] = tm[j]-tm[j+1];
					++k;
				}
			}
		}
		//cout << ">> " << k << endl;
		if(k < ans)
		{
			ans = k;
		}
	}
	if(ans == 1000000)
		cout << -1 << endl;
	else
		cout << ans << endl;
	return 0;
}




















Measured memory_bytes: 1024