#include<bits/stdc++.h>

using namespace std;

const int MAXN = 18;

int n;
int a[MAXN][2], b[MAXN];
int f[1 << MAXN][55];

int main() {
  ios_base::sync_with_stdio(false); cin.tie(NULL);

  cin >> n;
  for(int j = 0; j < 2; ++j) {
    for(int i = 0; i < n; ++i) cin >> a[i][j];
  }

  memset(f, 60, sizeof f);

  f[0][0] = 0;
  for(int mask = 0; mask + 1 < (1 << MAXN); ++mask) {
    int cur = __builtin_popcount(mask);
    int current_cost = 0;
    int cst[MAXN];
    for(int i = 0; i < n; ++i) {
      cst[i] = current_cost;
      if(!(mask & (1 << i))) {
        ++current_cost;
      }
    }
    for(int j = 0; j <= 50; ++j) {
      for(int i = 0; i < n; ++i) {
        if(!(mask & (1 << i))) {
          int dst = abs(i - cur) % 2;
          if(a[i][dst] >= j) {
            f[mask ^ (1 << i)][a[i][dst]] = min(f[mask ^ (1 << i)][a[i][dst]], f[mask][j] + cst[i]);
          }
        }
      }
    }
  }

  int ans = (int) 1e9;
  for(int i = 0; i <= 50; ++i) {
    ans = min(ans, f[(1 << n) - 1][i]);
  }

  if(ans > 2000000) {
    cout << -1;
  }
  else cout << ans;

  return 0;
}
