#define _USE_MATH_DEFINES
#define _SILENCE_CXX17_C_HEADER_DEPRECATION_WARNING
#define _SILENCE_ALL_CXX17_DEPRECATION_WARNINGS
#define _CRT_SECURE_NO_WARNINGS
//#include <bits/stdc++.h>

#include <cstdio>
#include <cmath>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <bitset>
#include <unordered_map>
#include <unordered_set>
#include <cassert>
#include <fstream>
#include <array>
#include <string>
#include <cstring>
#include <functional>
#include <ctime>
#include <iostream>
#include <unordered_set>

#include <nmmintrin.h>
#include <mmintrin.h>
#include <emmintrin.h>


using namespace std;

#define dprint(Exp,...) if(Exp){fprintf(stderr, __VA_ARGS__);}
#define printe(...) fprintf(stderr, __VA_ARGS__);
//#define printe(...) void();
#define printE(...) fprintf(stderr, __VA_ARGS__);
//#define printE(...) void();


#define PrtExp(_Exp)  cerr<< #_Exp <<" = "<< (_Exp)
#define PrtExpN(_Exp)  cerr<< #_Exp <<" = "<< (_Exp) <<"\n"

#define SINT(n) scanf("%d",&n)
#define SINT2(n,m) scanf("%d %d",&n,&m)
#define SINT3(n,m,o) scanf("%d %d %d",&n,&m,&o)
#define SINT4(n,m,o,P) scanf("%d %d %d %d",&n,&m,&o,&P)
#define SINT5(n,m,o,P,q) scanf("%d %d %d %d %d",&n,&m,&o,&P,&q)
#define SLL(n) scanf("%lld",&n)
#define SLL2(n,m) scanf("%lld %lld",&n,&m)
#define SLL3(n,m,o) scanf("%lld %lld %lld",&n,&m,&o)
#define SST(s) scanf("%s",s)
#define SCH(c) scanf("%c",&c)

#define GC() getchar()

#define PINT(n) printf("%d",(int)(n))
#define PINT2(n,m) printf("%d %d",(int)(n),(int)(m))
#define PINT3(n,m,l) printf("%d %d %d",(int)(n),(int)(m),(int)(l))
#define PLL(n) printf("%lld",(long long)(n))
#define PST(s) printf("%s",(s))
#define PCH(s) printf("%c",(s))

#define PINTN(n) printf("%d\n",(int)(n))
#define PINT2N(n,m) printf("%d %d\n",(int)(n),(int)(m))
#define PINT3N(n,m,l) printf("%d %d %d\n",(int)(n),(int)(m),(int)(l))
#define PLLN(n) printf("%lld\n",(long long)(n))
#define PSTN(s) printf("%s\n",(s))
#define PCHN(s) printf("%c\n",(s))

#define PSP() printf(" ")
#define PN() printf("\n")

#define PC(c) putchar(c)
#define CSP (' ')
#define SN ("\n")

#define rep(i,a) for(int i=0;i<a;i++)
#define reP(i,a) for(int i=0;i<=a;i++)
#define Rep(i,a) for(int i=a-1;i>=0;i--)
#define ReP(i,a) for(int i=a;i>=0;i--)

#define rEp(i,a) for(i=0;i<a;i++)
#define rEP(i,a) for(i=0;i<=a;i++)
#define REp(i,a) for(i=a-1;i>=0;i--)
#define REP(i,a) for(i=a;i>=0;i--)

#define repft(i,a,b) for(int i=a;i<b;i++)
#define repfT(i,a,b) for(int i=a;i<=b;i++)
#define Repft(i,a,b) for(int i=a-1;i>=b;i--)
#define RepfT(i,a,b) for(int i=a;i>=b;i--)

#define foreach(a,it) for(auto it = a.begin(); it != a.end(); ++it)

#define FILL(a,v) fill(begin(a),end(a), v)
#define FILL0(a) memset(a,0,sizeof(a))
#define FILL1(a) memset(a,-1,sizeof(a))

typedef long long ll;

typedef unsigned long long ull;
typedef pair<int, int> Pi;
typedef pair<ll, ll>   Pll;


const int INF = 1'010'000'000; // 0x3C33'6080
const ll INFLL = 0x1f1f1f1f1f1f1f1fLL;//2,242,545,357,980,376,863

template <class A, class B> inline ostream& operator<<(ostream& st, const pair<A, B>& P) { return st << "(" << P.first << "," << P.second << ")"; };
template <class A, class B> inline pair<A, B> operator+(const pair<A, B>& P, const pair<A, B>& Q) { return pair<A, B>(P.first + Q.first, P.second + Q.second); };
template <class A, class B> inline pair<A, B> operator-(const pair<A, B>& P, const pair<A, B>& Q) { return pair<A, B>(P.first - Q.first, P.second - Q.second); };

#define fs  first
#define sc  second

int bitCount(unsigned long long bits) {
#if _MSC_VER >= 1920 || __INTEL_COMPILER
	return _mm_popcnt_u64(bits);
#else
	return __builtin_popcountll(bits);
#endif 
}
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }




template <class T>
struct fenwick_tree {
	int n;
	std::vector<T> x;
	fenwick_tree(int n_ = 0) : n(n_), x(n + 1, 0) {}
	int size() const { return n; }
	T sum(int r) const {
		T S = 0; ++r;
		for (r = r - 1; r >= 0; r = (r & (r + 1)) - 1) S += x[r];
		return S;
	}
	T sum(int l, int r) const { return sum(r) - sum(l); }
	void add(int k, const T& a) {
		for (; k < n; k |= k + 1) x[k] += a;
	}
	void set(int k, const T& a) { add(k, a - sum(k, k + 1)); }
};


template<typename FI>
void parted_rotate(FI first1, FI last1, FI first2, FI last2)
{
	if (first1 == last1 || first2 == last2) return;
	FI next = first2;
	while (first1 != next) {
		std::iter_swap(first1++, next++);
		if (first1 == last1) first1 = first2;
		if (next == last2) {
			next = first2;
		} else if (first1 == first2) {
			first2 = next;
		}
	}
}

template<typename BI>
bool next_combination_imp(BI first1, BI last1, BI first2, BI last2)
{
	if (first1 == last1 || first2 == last2) return false;
	auto target = last1; --target;
	auto last_elem = last2; --last_elem;
	// find right-most incrementable element: target
	while (target != first1 && !(*target < *last_elem)) --target;
	if (target == first1 && !(*target < *last_elem)) {
		parted_rotate(first1, last1, first2, last2);
		return false;
	}
	// find the next value to be incremented: *next
	auto next = first2;
	while (!(*target < *next)) ++next;
	std::iter_swap(target++, next++);
	parted_rotate(target, last1, next, last2);
	return true;
}

// INVARIANT: is_sorted(first, mid) && is_sorted(mid, last)
template<typename BI>
inline bool next_combination(BI first, BI mid, BI last)
{
	return next_combination_imp(first, mid, mid, last);
}

// INVARIANT: is_sorted(first, mid) && is_sorted(mid, last)
template<typename BI>
inline bool prev_combination(BI first, BI mid, BI last)
{
	return next_combination_imp(mid, last, first, mid);
}

int mergecount(vector<int>& a) {
	int count = 0;
	int n = a.size();
	if (n > 1) {
		vector<int> b(a.begin(), a.begin() + n / 2);
		vector<int> c(a.begin() + n / 2, a.end());
		count += mergecount(b);
		count += mergecount(c);
		for (int i = 0, j = 0, k = 0; i < n; ++i)
			if (k == c.size())       a[i] = b[j++];
			else if (j == b.size())  a[i] = c[k++];
			else if (b[j] <= c[k])   a[i] = b[j++];
			else { a[i] = c[k++]; count += n / 2 - j; }
	}
	return count;
}

Pi vw[21];

int main() {
	int n;
	int a[20][2];
	cin >> n;

	rep(i, n) cin >> a[i][0];
	rep(i, n) cin >> a[i][1];

	int c[20];
	rep(i, n) c[i] = i;

	const int an = (n + 1) / 2;

	int ret = INF;

	do {
		//rep(i, an)cout << c[i] << " "; cout << endl;
		vector<Pi> v(an);
		vector<Pi> w(n - an);
		rep(i, an) {
			v[i].first = a[c[i]][c[i] % 2];
			v[i].second = c[i];
		}
		rep(i, n-an) {
			w[i].first = a[c[an+i]][1 - c[an+i] % 2];
			w[i].second = c[an+i];
		}
		sort(v.begin(), v.end());
		sort(w.begin(), w.end());
		//for (auto z : v) cout << z; cout << endl;
		rep(i, n - an) {
			vw[i * 2 + 0] = v[i];
			vw[i * 2 + 1] = w[i];
		}
		if (n % 2 == 1) vw[n - 1] = v.back();

		//rep(i, n) cout << vw[i]; cout << endl;
		
		bool ng = false;
		rep(i, n - 1) {
			if (vw[i].first > vw[i + 1].first) ng = true;
		}
		if (ng) continue;

		vector<int> p(n);
		rep(i, n) p[i] = vw[i].second; 
		int r = mergecount(p);
		ret = min(ret, r);
	} while (next_combination(c, c + an, c + n));
	
	cout << (ret == INF ? -1 : ret) << endl;

}

Measured memory_bytes: 256