#include <bits/stdc++.h>
#define LLI long long int
#define FOR(v, a, b) for(LLI v = (a); v < (b); ++v)
#define FORE(v, a, b) for(LLI v = (a); v <= (b); ++v)
#define REP(v, n) FOR(v, 0, n)
#define REPE(v, n) FORE(v, 0, n)
#define REV(v, a, b) for(LLI v = (a); v >= (b); --v)
#define ALL(x) (x).begin(), (x).end()
#define RALL(x) (x).rbegin(), (x).rend()
#define ITR(it, c) for(auto it = (c).begin(); it != (c).end(); ++it)
#define RITR(it, c) for(auto it = (c).rbegin(); it != (c).rend(); ++it)
#define EXIST(c,x) ((c).find(x) != (c).end())
#define fst first
#define snd second
#define popcount __builtin_popcount
#define UNIQ(v) (v).erase(unique(ALL(v)), (v).end())
#define bit(i) (1LL<<(i))

#ifdef DEBUG
#include <misc/C++/Debug.cpp>
#else
#define dump(...) ((void)0)
#endif

#define gcd __gcd

using namespace std;
template <class T> constexpr T lcm(T m, T n){return m/gcd(m,n)*n;}

template <typename I> void join(ostream &ost, I s, I t, string d=" "){for(auto i=s; i!=t; ++i){if(i!=s)ost<<d; ost<<*i;}ost<<endl;}
template <typename T> istream& operator>>(istream &is, vector<T> &v){for(auto &a : v) is >> a; return is;}
template <typename T, typename U> bool chmin(T &a, const U &b){return (a>b ? a=b, true : false);}
template <typename T, typename U> bool chmax(T &a, const U &b){return (a<b ? a=b, true : false);}
template <typename T, size_t N, typename U> void fill_array(T (&a)[N], const U &v){fill((U*)a, (U*)(a+N), v);}

struct Init{
  Init(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(12);
    cerr << fixed << setprecision(12);
  }
}init;



template <typename F>
struct FixPoint : F{
  explicit constexpr FixPoint(F &&f) noexcept : F(std::forward<F>(f)){}

  template <typename... Args>
  constexpr decltype(auto) operator()(Args &&... args) const {
    return F::operator()(*this, std::forward<Args>(args)...);
  }
};

template <typename F>
static inline constexpr decltype(auto) make_fix_point(F &&f){
  return FixPoint<F>(std::forward<F>(f));
}

template <typename T>
inline auto make_vector(int N, int M, const T &value){
  return std::vector<std::vector<T>>(N, std::vector<T>(M, value));
}


int main(){
  int N;
  while(cin >> N){
    vector<int> A(N), B(N); cin >> A >> B;

    vector<vector<int>> d(N);

    REP(i,N){
      d[i].resize(N);

      REP(j,N){
        if((i-j) % 2 == 0){
          d[i][j] = A[i];
        }else{
          d[i][j] = B[i];
        }
      }
    }

    auto dp = make_vector(18, 1<<18, INT_MAX);
    auto check = make_vector(18, 1<<18, false);

    auto f =
      make_fix_point([&](auto &&f, int i, int j) -> LLI{
                       if(check[i][j]) return dp[i][j];
                       check[i][j] = true;

                       if(not (j & bit(i))) return dp[i][j];
                       
                       int p = __builtin_popcount(j);

                       if(p == 1) return dp[i][j] = 0;

                       int t = __builtin_popcount(j & ~(bit(i+1) - 1));

                       REP(k,N){
                         if(not (j & bit(k))) continue;
                         
                         auto r = f(k, j ^ bit(i));

                         if(d[k][p-2] <= d[i][p-1]){
                           chmin(dp[i][j], r + t);
                         }
                       }

                       return dp[i][j];
                     });
    
    
    LLI ans = INT_MAX;

    REP(i,N){
      chmin(ans, f(i, bit(N)-1));
    }

    if(ans == INT_MAX){
      cout << -1 << endl;
    }else{
      cout << ans << endl;
    }
  }

  return 0;
}


Measured memory_bytes: 19840