#include <stdio.h>
#include <cstdio>
#include <iostream>
#include <iomanip>
#include <queue>
#include <set>
#include <vector>
#include <string>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <complex>

int main(){

  // read problem
  long long int N, tmp;
  std::vector<long long int> A, B;
  scanf("%lld", &N);
  for(long long int i = 0; i < N; i++){
    scanf("%lld", &tmp);
    A.push_back(tmp);
  }
  for(long long int i = 0; i < N; i++){
    scanf("%lld", &tmp);
    B.push_back(tmp);
  }

  /*std::cerr << "N: " << N << std::endl;
  std::cerr << "A:" << std::endl;
  for(long long int i = 0; i < N; i++){
    std::cerr << A[i] << " ";
  }std::cerr << std::endl;
  std::cerr << "B:" << std::endl;
  for(long long int i = 0; i < N; i++){
    std::cerr << B[i] << " ";
  }std::cerr << std::endl;*/

  // solve problem
  long long int halfN = N/2;
  long long int possible_flag = 0;
  long long int ans = 1e9;
  long long int flg_tmp, ans_tmp, sum_tmp;
  long long int neven = N/2 + N%2;
  long long int nodd = N/2;
  //std::cerr << "halfN: " << halfN << std::endl;

  // no flip
  std::vector<std::pair<long long int, long long int> > odd, even;
  std::vector<std::pair<long long int, long long int> > all;
  std::vector<long long int> tmp_count(N);

  // make even, odd
  for(long long int i = 0; i < N/2+N%2; i++){
    even.push_back(std::make_pair(A[2*i], 2*i));
  }
  
  for(long long int i = 0; i < N/2; i++){
    odd.push_back(std::make_pair(A[2*i+1], 2*i+1));
  }

  std::sort(even.begin(), even.end());
  std::sort(odd.begin(), odd.end());

  for(long long int i = 0; i < N; i++){
    if((i&1) == 0){
      all.push_back(even[i/2]);
    }
    else{
      all.push_back(odd[i/2]);
    }
  }

  // check the flip
  flg_tmp = 1;
  for(long long int i = 0; i < N-1; i++){
    if(all[i].first > all[i+1].first){
      flg_tmp = 0;
      break;
    }
  }

  // update answer
  if(flg_tmp){
    possible_flag = 1;

    ans_tmp = 0;
    for(long long int i = 0; i < N; i++){
      tmp_count[i] = 0;
    }
    for(long long int i = 0; i < N; i++){
      for(long long int j = N-1; j > all[i].second; j--){
        ans_tmp += tmp_count[j];
      }
      tmp_count[all[i].second] = 1;
    }

    ans = std::min(ans, ans_tmp); 
  }


  long long int x1, y1, x2, y2;
  for(long long int k = 1; k <= halfN; k++){
    std::cerr << "k: " << k << std::endl;
    // make group
    for(long long int T1 = (1<<k)-1; T1 < (1<<neven); x1 = T1&(-T1), y1 = T1+x1, T1 = (((T1 & ~y1) / x1) >> 1) | y1){
      for(long long int T2 = (1<<k)-1; T2 < (1<<nodd); x2 = T2&(-T2), y2 = T2+x2, T2 = (((T2 & ~y2) / x2) >> 1) | y2){

        std::cerr << "(T1, T2): " << T1 << " " << T2 << std::endl;
        // make even odd
        even.clear();
        odd.clear();
        all.clear();
        for(long long int i = 0; i < N; i++){
          // even
          if((i&1) == 0){
            // flip
            if((T1>>(i/2))&1){
              odd.push_back(std::make_pair(B[i], i));
            }
            else{
              even.push_back(std::make_pair(A[i], i));
            }
          }
          // odd
          else{
            if((T2>>(i/2))&1){
              even.push_back(std::make_pair(B[i], i));
            }
            else{
              odd.push_back(std::make_pair(A[i], i));
            }
          }
        }

        // check answer candidate
        std::sort(even.begin(), even.end());
        std::sort(odd.begin(), odd.end());

        for(long long int i = 0; i < N; i++){
          if((i&1) == 0){
            all.push_back(even[i/2]);
          }
          else{
            all.push_back(odd[i/2]);
          }
        }

        // check the flip
        flg_tmp = 1;
        for(long long int i = 0; i < N-1; i++){
          if(all[i].first > all[i+1].first){
            flg_tmp = 0;
            break;
          }
        }

        // update answer
        if(flg_tmp){
          possible_flag = 1;

          ans_tmp = 0;
          for(long long int i = 0; i < N; i++){
            tmp_count[i] = 0;
          }
          for(long long int i = 0; i < N; i++){
            for(long long int j = N-1; j > all[i].second; j--){
              ans_tmp += tmp_count[j];
            }
            tmp_count[all[i].second] = 1;
          }

          ans = std::min(ans, ans_tmp);
          
        }

      }
    }

  
  }

  std::cerr << "Answer:" << std::endl;
  if(possible_flag){
    std::cout << ans << std::endl;
  }
  else{
    std::cout << -1 << std::endl;
  }

  return 0;


  /*
  std::cerr << "T runs for all subset including k elements" << std::endl;
  long long int k = 3;
  long long int x, y;
  
  for(long long int T = (1<<k)-1; T < (1<<N); x = T&(-T), y = T+x, T = (((T & ~y) / x) >> 1) | y {
    std::cerr << T << std::endl;
    print_subset(N, T);
  }
  */

}


Measured memory_bytes: 256