#include <bits/stdc++.h>
using namespace std;

#define INF_LL (int64)1e18
#define INF (int32)1e9
#define REP(i, n) for(int64 i = 0;i < (n);i++)
#define FOR(i, a, b) for(int64 i = (a);i < (b);i++)
#define all(x) x.begin(),x.end()
#define fs first
#define sc second

using int32 = int_fast32_t;
using uint32 = uint_fast32_t;
using int64 = int_fast64_t;
using uint64 = uint_fast64_t;
using PII = pair<int32, int32>;
using PLL = pair<int64, int64>;

const double eps = 1e-10;

template<typename A, typename B>inline void chmin(A &a, B b){if(a > b) a = b;}
template<typename A, typename B>inline void chmax(A &a, B b){if(a < b) a = b;}

template<typename T>
vector<T> make_v(size_t a){return vector<T>(a);}

template<typename T,typename... Ts>
auto make_v(size_t a,Ts... ts){
	return vector<decltype(make_v<T>(ts...))>(a,make_v<T>(ts...));
}

template<typename T,typename U,typename... V>
typename enable_if<is_same<T, U>::value!=0>::type
fill_v(U &u,const V... v){u=U(v...);}

template<typename T,typename U,typename... V>
typename enable_if<is_same<T, U>::value==0>::type
fill_v(U &u,const V... v){
	for(auto &e:u) fill_v<T>(e,v...);
}

template<typename CommutativeMonoid>
class FenwickTree{
public:
  using value_structure = CommutativeMonoid;
  using value_type = typename CommutativeMonoid::value_type;
  using size_type = ::std::size_t;

private:
  ::std::vector<value_type> tree;
  size_type N;

  static value_type calc(const value_type& a, const value_type& b){
    return value_structure::operation(a, b);
  }

public:
  FenwickTree(){}
  FenwickTree(const size_type& N):N(N+10), tree(N+11, value_structure::identity()){}
  FenwickTree(const FenwickTree& bit):tree(bit.tree), N(bit.N){}

  void update(size_type k, const value_type& diff){ // update k in [1, N]
    for(;k <= N;k += k & -k){
      tree[k] = calc(tree[k], diff);
    }
  }

  value_type query(size_type k) const { // sum of [1, k]
    value_type res = value_structure::identity();
    for(;k > 0;k -= k & -k){
      res = calc(res, tree[k]);
    }
    return res;
  }

  void updatez(size_type k, value_type v){ // 0-indexed
    update(k+1, v);
  }

  value_type queryz(size_type k) const { // [0, k)
    return query(k+1);
  }

  size_type search(const std::function<bool(value_type)>& f) const { // Find k :[0, k) -> True, [0, k-1) -> False
    if(f(value_structure::identity()))
      return 0;
    if(!f(query(N)))
      return N+1;
    value_type x = value_structure::identity();
    size_type k = 1, idx = 0;
    while(k <= N) k <<= 1;
    k >>= 1;
    for(;k > 0;k >>= 1){
      if((idx|k) <= N && !f(tree[idx|k]+x))
        x = calc(x, tree[idx |= x]);
    }
    return idx+1;
  }

  size_type size() const {return N;}
};

class PlusMonoid{
public:
  using value_type = int_fast64_t;
  static constexpr value_type identity(){return 0;}

  static value_type operation(const value_type& a, const value_type& b){
    return a+b;
  }

};

int main(void){
	cin.tie(0);
	ios::sync_with_stdio(false);

	int64 N;
	cin >> N;
	vector<int64> A(N), B(N);
	REP(i, N) cin >> A[i];
	REP(i, N) cin >> B[i];
	int64 res = INF_LL;
	REP(i, 1 << N) {
	  vector<PLL> a[2];
	  REP(j, N) {
	    if ((j % 2)^(i >> j & 1)) {
	      a[1].emplace_back((j % 2 ? A[j] : B[j]), j);
	    } else {
        a[0].emplace_back((j % 2 ? B[j] : A[j]), j);
	    }
	  }
//	  cout << "a0: ";
//	  REP(j, a[0].size()) cout << a[0][j].fs << " ";
//	  cout << "a1: ";
//    REP(j, a[1].size()) cout << a[1][j].fs << " ";
//    cout << endl;

	  sort(all(a[0])); sort(all(a[1]));
	  if (a[0].size() != a[1].size() + N%2) continue;
	  FenwickTree<PlusMonoid> bit(N);
	  int64 sum = 0, last = -1;
	  REP(j, N) {
	    int64 x = a[j%2][j/2].fs, idx = a[j%2][j/2].sc;
	    if (last > x) {
	      sum = INF_LL;
	      break;
	    }
	    last = x;
	    sum += idx-(bit.queryz(idx));
	    bit.updatez(idx, 1);
	  }
	  chmin(res, sum);
	}
	cout << (res == INF_LL ? -1 : res) << endl;
}


Measured memory_bytes: 256