#include <iostream>
#include <vector>
#include <array>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <string>
#include <sstream>
#include <algorithm>
#include <random>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <cmath>
#include <cassert>
#include <climits>
#include <bitset>
#include <functional>
#include <iomanip>
#include <random>


#define FOR_LT(i, beg, end) for (int i = beg; i < end; i++)
#define FOR_LE(i, beg, end) for (int i = beg; i <= end; i++)
#define FOR_DW(i, beg, end) for (int i = beg; end <= i; i--)

using namespace std;

struct P {
	int c;
	int p;
	int i;
};

int count_sort(vector<P>& ps, int n)
{
	int c = 0;
	FOR_LT(i, 0, n) {
		FOR_LT(j, 0, i) {
			if (ps[j].i > ps[i].i) c++;
		}
	}
	return c;
}

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout << fixed << setprecision(20);

	int n; cin >> n;
	vector<int> as(n);
	for (int i = 0; i < n; i++) {
		cin >> as[i];
	}
	vector<int> bs(n);
	for (int i = 0; i < n; i++) {
		cin >> bs[i];
	}

	int ans = INT_MAX;
	vector<P> ps(n);
	FOR_LT(s, 0, (1 << n)) {
		FOR_LT(i, 0, n) {
			ps[i].i = i;
			if ((s >> i) & 1) {
				ps[i].c = bs[i];
				ps[i].p = (i + 1) & 1;
			}
			else {
				ps[i].c = as[i];
				ps[i].p = i & 1;
			}
		}
		stable_sort(ps.begin(), ps.end(), [](const auto & lhs, const auto & rhs) {
			return lhs.c < rhs.c;
			});

		bool is_ok = true;
		FOR_LT(j, 0, n) {
			if (ps[j].p == (j & 1)) {
				int si = ps[j].i;
				int sv = INT_MAX;
				FOR_LT(k, j + 1, n) {
					if (ps[k].c != ps[j].c) break;
					if (ps[j].p != (k & 1)) continue;
					if (ps[k].p != (j & 1)) continue;

					if (ps[k].i < si) {
						si = ps[k].i;
						sv = k;
					}
				}
				if (sv != INT_MAX) {
					swap(ps[j], ps[sv]);
				}
				continue;
			}

			bool is_found = false;
			int  si = INT_MAX;
			int  sv = INT_MAX;
			FOR_LT(k, j + 1, n) {
				if (ps[k].c != ps[j].c) break;
				if (ps[j].p != (k & 1)) continue;
				if (ps[k].p != (j & 1)) continue;

				is_found = true;
				if (ps[k].i < si) {
					si = ps[k].i;
					sv = k;
				}
			}
			if (!is_found) {
				is_ok = false;
				break;
			}
			swap(ps[j], ps[sv]);
		}
		if (!is_ok) continue;

		int count = count_sort(ps, n);

		ans = min(ans, count);
	}

	if (ans == INT_MAX) {
		int* hoge = 0;
		*hoge = 0;
		cout << -1 << endl;
	}
	else {
		cout << ans << endl;
	}

	return 0;
}