#include <bits/stdc++.h>
using namespace std;
const int INF = 0x3f3f3f3f;
const int MOD = 20010905;
const int maxn = 1e5 + 10;
int n, a[100], b[100], t[100];
struct node {
  int val;
  int pos;
  int flag;
} s[100];
int check(int x) {
  for (int i = 1; i <= n; i++) {
    if ((x >> (i - 1)) & 1)
      s[i] = node{a[i], i, 1}, t[i] = a[i];
    else
      s[i] = node{b[i], i, 0}, t[i] = b[i];
  }
  sort(t + 1, t + n + 1);
  int cnt = 0;
  for (int i = 1; i <= n; i++) {
    bool flag = false;
    for (int j = i; j <= n; j++) {
      if (s[j].val == t[i] && ((abs(s[j].pos - i) & 1) ^ s[j].flag)) {
        flag = true;
        for (int k = j - 1; k >= i; k--) {
          swap(s[k], s[k + 1]);
          cnt++;
        }
        break;
      }
    }
    if (!flag) return INF;
  }
  return cnt;
}
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) scanf("%d", &a[i]);
  for (int i = 1; i <= n; i++) scanf("%d", &b[i]);
  int ans = INF;
  for (int i = 0; i <= (1 << n) - 1; i++) ans = min(ans, check(i));
  if (ans == INF)
    printf("-1\n");
  else
    printf("%d\n", ans);
  return 0;
}
