#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <stack>
#include <queue>
#include <cmath>
#include <tuple>
#include <cstdio>
#include <bitset>
#include <sstream>
#include <iterator>
#include <numeric>
#include <map>
#include <cstring>
#include <set>
#include <functional>
#include <iomanip>

using namespace std;

#define DEBUG_ //!!$BDs=P;~$K%3%a%s%H%"%&%H(B!!
#ifdef DEBUG_
#define dump(x)  cerr << #x << " = " << (x) << endl;
#else
#define dump(x)  ;
#endif

#define equals(a,b) (fabs((a)-(b)) < EPS)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define SZ(x) ((int)(x).size())
#define pb push_back
#define eb emplace_back

//#define int long long

typedef long long LL;
typedef vector<int> VI;
typedef vector<LL> VL;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef pair<LL, LL> PLL;

template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

    template <typename T>
std::string printVector(const std::vector<T> &data)
{
    std::stringstream ss;
    std::ostream_iterator<T> out_it(ss, ", ");
    ss << "[";
    std::copy(data.begin(), data.end() - 1, out_it);
    ss << data.back() << "]";
    return ss.str();
}

template <typename T>
void print_array(const T &ary, int size){
    REP(i,size){
        cout << ary[i] << " ";
    }
    cout << endl;
}

const int mod = 1e9+7;
const LL LINF = 1001002003004005006ll;
const int INF = 1001001001;
const double EPS = (1e-10);
const long double PI = 3.14159265358979323846264338327950288419716939937510582097494459230781640628620899;
int dx[] = {0,0,-1,1};
int dy[] = {-1,1,0,0};


signed main(int argc, char const *argv[])
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << setprecision(12);
    int n; cin >> n;
    VI a(n),b(n);
    REP(i,n) cin >> a[i], a[i]--;
    REP(i,n) cin >> b[i], b[i]--;

    int ret = INF;
    REP(i,1LL<<n){
        VI v;
        vector<PII> need(50),v0,v1;
        REP(j,n){
            if(i&1LL<<j){
                v.eb(a[j]);
                if(j%2 == 0){
                    need[a[j]].first++;
                    v0.eb(a[j],j);
                }else{
                    need[a[j]].second++;
                    v1.eb(a[j],j);
                }
            }else{
                v.eb(b[j]);
                if(j%2==0){
                    need[b[j]].second++;
                    v1.eb(b[j],j);
                }else{
                    need[b[j]].first++;
                    v0.eb(b[j],j);
                }
            }
        }
        sort(v.begin(),v.end());
        vector<PII> vp(50);
        REP(j,n){
            if(j%2 == 0) vp[v[j]].first++;
            else vp[v[j]].second++;
        }
        if(need != vp) continue;

        sort(v0.begin(),v0.end());
        sort(v1.begin(),v1.end());
        VI sorted;
        REP(i,max(v0.size(),v1.size())){
            if(i < v0.size()) sorted.eb(v0[i].second);
            if(i < v1.size()) sorted.eb(v1[i].second);
        }

        int tmp = 0;
        VI num(n);
        REP(j,n){
            FOR(k,sorted[j],n){
                tmp += num[k];
            }
            num[sorted[j]]++;
        }
        chmin(ret,tmp);

    }
    if(ret == INF) cout << -1 << endl;
    else cout << ret << endl;


}

Measured memory_bytes: 256