//#pragma GCC optimize("O3")
#include<bits/stdc++.h>
#define ll long long int
#define ld long double
#define pb push_back
#define pf pop_front
#define mp make_pair
#define mod 1000000007
#define fio ios_base::sync_with_stdio(false);cin.tie(NULL);
#define all(x) x.begin(),x.end()
#define F first
#define S second
#define fo(i,n) for(int i=0;i<(n);i++)
#define inp(a) int a;cin>>a;
#define inpa(a,n)vector<int> a(n);fo(i,n)cin>>a[i];
#define printclock cerr<<"Time : "<<1000*(ld)clock()/(ld)CLOCKS_PER_SEC<<"ms\n";
using namespace std;
#define int ll
#define MAX 50
#define INF (int)1e18

template<class T> ostream& operator<<(ostream& cout,set<T> V)
{cout<<"[ ";for(auto v:V)cout<<v<<' ';return cout<<']';}
template<class T> ostream& operator<<(ostream& cout,vector<T> V)
{cout<<"[ ";for(auto v:V)cout<<v<<' ';return cout<<']';}
template<class L,class R> ostream& operator<<(ostream& cout,pair<L, R> P)
{return cout<<'('<<P.F<<','<< P.S<<')';}


int n;
vector<pair<int,int>> a;





int f(vector<int> a)
{
	// cerr<<a<<'\n';
	int n=a.size();
	int ans=0;
	fo(i,n)
	{
		int ind;
		for(ind=0;ind<n;ind++)
		{
			if(a[ind]==i)
				break;
		}
		while(ind!=i)
		{
			ans++;
			swap(a[ind],a[ind-1]);
			ind--;
		}
	}
	// cerr<<a<<","<<ans<<'\n';
	
	return ans;
}






signed main()
{
	fio
	cin>>n;
	a.resize(n);
	fo(i,n)
	{
		cin>>a[i].F;
	}
	fo(i,n)
	{
		cin>>a[i].S;
	}
	int fans=INF;

	for(int mask=0;mask<(1<<n);mask++)
	{
		vector<pair<int,int>> b(n);
		fo(j,n)
		{
			if(mask&(1<<j))
			{
				b[j]={a[j].S,-j-1};
			}
			else
			{
				b[j]={a[j].F,j+1};
			}
		}
		sort(all(b));
		
		// cerr<<mask<<" : "<<b<<'\n';
		
		int i=0;
		bool poss=1;
		vector<pair<int,int>> c(n);
		while(i<n)
		{
			int j=i;
			int e=0,o=0;
			while(j<n && b[i].F==b[j].F)
			{
				int ind=b[j].S;
				ind=abs(ind);
				ind--;
				if(mask&(1<<ind))
				{
					if(ind%2==0)
					{
						o++;
					}
					else
					{
						e++;
					}
				}
				else
				{
					if(ind%2==0)
					{
						e++;
					}
					else
					{
						o++;
					}
				}
				if(j%2==0)
					e--;
				else
					o--;
				j++;
			}
			for(int temp=i;temp<j;temp++)
			{
				c[(int)abs(b[temp].S)-1]={i,j-1};
			}
			
			
			if(o || e)
			{
				poss=0;
				break;
			}
			i=j;
		}
		
		
		if(!poss)
			continue;
		
		
		
		set<int> ol,el;
		fo(ii,n)
		{
			if(ii%2)
				ol.insert(ii);
			else
				el.insert(ii);
		}
		
		// cerr<<c<<'\n';
		
		// int ans=0;
		vector<int> ans(n);
		fo(ii,n)
		{
			
			// cerr<<ii<<'-'<<ol<<' '<<el<<'\n';
			
			if(mask&(1<<ii))
			{
				if(ii%2)
				{
					auto itr=el.lower_bound(c[ii].F);
					if(itr==el.end())
					{
						poss=0;
						break;
					}
					// ans+=abs((*itr)-ii);
					ans[*itr]=ii;
					el.erase(itr);
				}
				else
				{
					auto itr=ol.lower_bound(c[ii].F);
					if(itr==ol.end())
					{
						poss=0;
						break;
					}
					// ans+=abs((*itr)-ii);
					ans[*itr]=ii;
					ol.erase(itr);
				}
			}
			else
			{
				if(ii%2)
				{
					auto itr=ol.lower_bound(c[ii].F);
					if(itr==ol.end() || (*itr)>c[ii].S)
					{
						poss=0;
						break;
					}
					// ans+=abs((*itr)-ii);
					ans[*itr]=ii;
					ol.erase(itr);
				}
				else
				{
					auto itr=el.lower_bound(c[ii].F);
					
					if(itr==el.end() || (*itr)>c[ii].S)
					{
						poss=0;
						break;
					}
					// ans+=abs((*itr)-ii);
					ans[*itr]=ii;
					el.erase(itr);
				}
			}
		}
		if(poss)
		{
			// if(fans>ans)
			// {
				// cerr<<b<<'\n';
				// cerr<<mask<<'\n';
			// }
			
			fans=min(fans,f(ans));
		}
	}
	
	if(fans==INF)
	{
		cout<<-1<<'\n';
	}
	else
	{
		// assert(fans%2==0);
		cout<<fans<<'\n';
	}
	printclock;
}

Measured memory_bytes: 256