#pragma GCC optimize ("Ofast")
#include<bits/stdc++.h>
using namespace std;
void *wmem;
char memarr[96000000];
template<class T> inline void walloc1d(T **arr, int x, void **mem = &wmem){
  static int skip[16] = {0, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1};
  (*mem) = (void*)( ((char*)(*mem)) + skip[((unsigned long long)(*mem)) & 15] );
  (*arr)=(T*)(*mem);
  (*mem)=((*arr)+x);
}
inline void rd(int &x){
  int k;
  int m=0;
  x=0;
  for(;;){
    k = getchar_unlocked();
    if(k=='-'){
      m=1;
      break;
    }
    if('0'<=k&&k<='9'){
      x=k-'0';
      break;
    }
  }
  for(;;){
    k = getchar_unlocked();
    if(k<'0'||k>'9'){
      break;
    }
    x=x*10+k-'0';
  }
  if(m){
    x=-x;
  }
}
inline void wt_L(char a){
  putchar_unlocked(a);
}
inline void wt_L(int x){
  int s=0;
  int m=0;
  char f[10];
  if(x<0){
    m=1;
    x=-x;
  }
  while(x){
    f[s++]=x%10;
    x/=10;
  }
  if(!s){
    f[s++]=0;
  }
  if(m){
    putchar_unlocked('-');
  }
  while(s--){
    putchar_unlocked(f[s]+'0');
  }
}
template<class S, class T> inline S chmin(S &a, T b){
  if(a>b){
    a=b;
  }
  return a;
}
template<class T> int coordcomp_L(int n, T arr[], int res[] = NULL, void *mem = wmem){
  int i;
  int k = 0;
  pair<T,int> *r;
  walloc1d(&r, n, &mem);
  for(i=(0);i<(n);i++){
    r[i].first = arr[i];
    r[i].second = i;
  }
  sort(r, r+n);
  if(res != NULL){
    for(i=(0);i<(n);i++){
      if(i && r[i].first != r[i-1].first){
        k++;
      }
      res[r[i].second] = k;
    }
  }
  else{
    for(i=(0);i<(n);i++){
      if(i && r[i].first != r[i-1].first){
        k++;
      }
      arr[r[i].second] = k;
    }
  }
  return k+1;
}
template<class T> int coordcomp_L(int n1, T arr1[], int n2, T arr2[], int res1[] = NULL, int res2[] = NULL, void *mem = wmem){
  int i;
  int k = 0;
  pair<T,int> *r;
  walloc1d(&r, n1+n2, &mem);
  for(i=(0);i<(n1);i++){
    r[i].first = arr1[i];
    r[i].second = i;
  }
  for(i=(0);i<(n2);i++){
    r[n1+i].first = arr2[i];
    r[n1+i].second = n1+i;
  }
  sort(r, r+n1+n2);
  for(i=(0);i<(n1+n2);i++){
    if(i && r[i].first != r[i-1].first){
      k++;
    }
    if(r[i].second < n1){
      if(res1!=NULL){
        res1[r[i].second] = k;
      }
      else{
        arr1[r[i].second] = k;
      }
    }
    else{
      if(res2!=NULL){
        res2[r[i].second-n1] = k;
      }
      else{
        arr2[r[i].second-n1] = k;
      }
    }
  }
  return k+1;
}
int N;
int A[18];
int B[18];
int dp[262144][37];
int solve(int mask, int bf){
  int i;
  int k;
  int x = 0;
  int c = 0;
  int res = 1073709056;
  if(dp[mask][bf] >= 0){
    return dp[mask][bf];
  }
  for(i=(0);i<(N);i++){
    if(!(mask & 1<<i)){
      x++;
    }
  }
  for(i=(0);i<(N);i++){
    if(mask & 1<<i){
      if((i+x)%2==0){
        k =A[i];
      }
      else{
        k =B[i];
      }
      if(k >= bf){
        chmin(res, solve(mask^(1<<i), k) + c);
      }
      c++;
    }
  }
  return dp[mask][bf] = res;
}
int main(){
  int i, j;
  wmem = memarr;
  int res;
  rd(N);
  {
    int cTE1_r3A;
    for(cTE1_r3A=(0);cTE1_r3A<(N);cTE1_r3A++){
      rd(A[cTE1_r3A]);
    }
  }
  {
    int xr20shxY;
    for(xr20shxY=(0);xr20shxY<(N);xr20shxY++){
      rd(B[xr20shxY]);
    }
  }
  coordcomp_L(N,A,N,B);
  for(i=(0);i<(1<<N);i++){
    int j;
    for(j=(0);j<(37);j++){
      dp[i][j] = -1;
    }
  }
  for(j=(0);j<(37);j++){
    dp[0][j] = 0;
  }
  res = solve((1<<N)-1, 0);
  if(res==1073709056){
    wt_L(-1);
    wt_L('\n');
  }
  else{
    wt_L(res);
    wt_L('\n');
  }
  return 0;
}
// cLay varsion 20200116-1 [beta]

// --- original code ---
// int N, A[18], B[18];
// int dp[262144][37];
// 
// int solve(int mask, int bf){
//   int i, k, x = 0, c = 0, res = int_inf;
//   if(dp[mask][bf] >= 0) return dp[mask][bf];
// 
//   rep(i,N) if(!(mask & 1<<i)) x++;
//   rep(i,N) if(mask & 1<<i){
//     k = if[(i+x)%2==0, A[i], B[i]];
//     if(k >= bf) res <?= solve(mask^(1<<i), k) + c;
//     c++;
//   }
// 
//   return dp[mask][bf] = res;
// }
// 
// {
//   int res;
//   rd(N,A(N),B(N));
//   coordcomp(N,A,N,B);
//   rep(i,1<<N) rep(j,37) dp[i][j] = -1;
//   rep(j,37) dp[0][j] = 0;
//   res = solve((1<<N)-1, 0);
//   wt(if[res==int_inf,-1,res]);
// }


Measured memory_bytes: 39168