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

int a[20], b[20] ;
int dp[ (1<<18) ][ 50 ] ;
int n ;
const int inf = 1e8 ;

int go ( int mask, int mx ) {
    if ( __builtin_popcount(mask) == n ) return 0 ;
    auto &rf = dp[mask][mx] ;
    if ( rf!=-1 ) return rf ;
    int cur = 0, v = __builtin_popcount(mask) ;
    rf = inf ;
    for ( int i = 0 ; i < n ; ++i ) {
        if ( mask&(1<<i) ) {
            --v ;
            continue ;
        }
        if ( (cur+v) % 2 && b[i] >= mx ) rf = min(rf, go ( mask|(1<<i), b[i] ) + cur) ;
        if ( (cur+v) % 2 == 0 && a[i] >= mx ) rf = min ( rf, go(mask|(1<<i), a[i])+cur ) ;
        ++cur;
    }
    return rf ;
}

int main() {
  //  freopen("input.txt", "r", stdin ) ;
    memset ( dp, -1, sizeof dp ) ;
    cin >> n ;
    for ( int i = 0 ; i < n ; ++i )
        cin >> a[i] ;
    for ( int i = 0 ; i < n ; ++i )
        cin >> b[i] ;
    if ( go(0,0) >= inf ) cout << "-1\n" ;
    else cout << go(0,0) << '\n' ;
}
