#include <cmath>
#include <cstdlib>
#include <iostream>
#include <bitset>
#include <deque>
#include <list>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <vector>
#include <algorithm>
#include <iterator>
#include <string>
#include <chrono>
#include <random>
#include <tuple>
#include <utility>
#include <fstream>
#include <complex>

const long INF = (1l << 30);
const long LINF = (1l << 60);

long n;
long a[2][19];
long ans = LINF;

long even_odd(long i, const long bit){//want even:0, want odd:1, ith wants to go to...
    if(i % 2 == 0){
        if(bit & (1 << i)){
            return 1;
        }else{
            return 0;
        }
    }else{
        if(bit & (1 << i)){
            return 0;
        }else{
            return 1;
        }
    }
}

int main(){
    scanf("%ld", &n);
    for(int i = 0; i < 2; i++){
        for(int j = 0; j < n; j++){
            scanf("%ld", &a[i][j]);
        }
    }
    for(long bit = 0; bit < (1 << n); bit++){
        //std::cout << std::bitset<8>(bit).to_string() << std::endl;
        std::vector<long> num[2];//[0]:even, [1]:odd
        std::vector<long> ord[2];//same
        for(int i = 0; i < n; i++){
            long eo = even_odd(i, bit);
            if(bit & (1 << i)){
                num[eo].push_back(a[1][i]);
            }else{
                num[eo].push_back(a[0][i]);
            }
            ord[eo].push_back(i);
        }
        /*
        for(int i = 0; i < 2; i++){
            if(i == 0){
                printf(" even\n");
            }else{
                printf(" odd\n");
            }
            for(int j = 0; j < ord[i].size(); j++){
                printf("  %2ld", ord[i][j]);
            }
            printf("\n");
            for(int j = 0; j < ord[i].size(); j++){
                printf("  %2ld", num[i][j]);
            }
            printf("\n");
        }
        //*/
        for(int i = 0; i < 2; i++){
            std::stable_sort(ord[i].begin(), ord[i].end(), [&](long x, long y){
                long num_x = a[(bit & (1 << x))?1:0][x];
                long num_y = a[(bit & (1 << y))?1:0][y];
                return num_x < num_y;
            });
        }
        if(!(ord[0].size() == ord[1].size() || ord[0].size() == ord[1].size() + 1)){
            continue;
        }
        std::vector<long> sorted;
        std::vector<long> s_ord;
        for(int i = 0; i < n; i++){
            s_ord.push_back(ord[i%2][i/2]);
            if(bit & (1 << i)){
                sorted.push_back(a[1][i]);
            }else{
                sorted.push_back(a[0][i]);
            }
        }
        long res = 0;
        for(int i = 0; i < n-1; i++){
            if(sorted[s_ord[i]] > sorted[s_ord[i+1]]){
                res = LINF;
            }
        }
        /*
        for(int i = 0; i < n; i++){
            printf("%2ld ", s_ord[i]);
        }
        printf("\n");
        for(int i = 0; i < n; i++){
            printf("%2ld ", sorted[s_ord[i]]);
        }
        printf("\n");
        //*/
        for(int i = 0; i < n; i++){
            for(int j = 0; j < i; j++){
                if(s_ord[j] > s_ord[i]){
                    res++;
                }
            }
        }
        //printf("  %ld\n", res);
        ans = std::min(ans, res);
        //printf("\n");
    }
    if(ans == LINF){
        printf("-1\n");
    }else{
        printf("%ld\n", ans);
    }
}


Measured memory_bytes: 384