#include <iostream>
#include <vector>

using namespace std;

const int inf = 1<<20;

int dp[1<<18][51];

int main() {
  int n; cin >> n;
  vector<int> la(n), lb(n);
  for (int &a: la) cin >> a;
  for (int &b: lb) cin >> b;
  for (int mask = 0; mask < (1<<n); ++mask) {
    for (int s = 0; s <= 50; ++s) dp[mask][s] = inf;
  }
  dp[0][0] = 0;
  for (int mask = 0; mask < (1<<n); ++mask) {
    int cnt = __builtin_popcount(mask);
    for (int s = 0; s <= 50; ++s) { 
      if (dp[mask][s] == inf) continue;
      int p = 0;
      for (int j = 0; j < n; ++j) { 
        int flag = 1<<j;
        if (mask & flag) continue;
        int t = (abs(j-cnt) % 2) ? lb[j] : la[j];
        if (t >= s) {
          dp[mask|flag][t] = min(dp[mask|flag][t], dp[mask][s] + p);
          // cerr << mask << " " << (mask|flag) << " " << s << " " << t << " " << dp[mask][s] << " " << p << " " << dp[mask|flag][t] << endl;
        }
        ++p;
      }
    }
  }
  int ans = inf;
  for (int t = 1; t <= 50; ++t) {
    ans = min(ans, dp[(1<<n)-1][t]);
  }
  if (ans == inf) {
    cout << -1 << endl;
  }
  else {
    cout << ans << endl;
  }
}

