let rec popcnt acc = function
  | 0 -> acc
  | n -> popcnt (acc + (n land 1)) (n lsr 1)
let popcnt = popcnt 0

let inf = 1145141919810

let () = Scanf.scanf "%d\n" @@ fun n ->
  let as_ = Array.init n @@ fun _ -> Scanf.scanf "%d " @@ fun a -> a in
  let bs = Array.init n @@ fun _ -> Scanf.scanf "%d " @@ fun b -> b in
  let dp = Array.make_matrix (1 lsl n) n inf in
  for i = 0 to n - 1 do
    dp.(1 lsl i).(i) <- i
  done;
  for mask = 1 to (1 lsl n) - 1 do
    for i = 0 to n - 1 do
      if 0 < mask land (1 lsl i) then begin
        let i' = popcnt mask - 1 in
        let x = if i mod 2 = i' mod 2 then as_.(i) else bs.(i) in
        for j = 0 to n - 1 do
          if mask land (1 lsl j) = 0 then begin
            let j' = i' + 1 in
            let y = if j mod 2 = j' mod 2 then as_.(j) else bs.(j) in
            if x <= y then
              dp.(mask lor (1 lsl j)).(j) <-
                min dp.(mask lor (1 lsl j)).(j) (max 0 (j - j') + dp.(mask).(i))
          end
        done
      end
    done
  done;
  let ans = Array.fold_left min inf dp.((1 lsl n) - 1) in
  Printf.printf "%d\n" @@ if inf <= ans then -1 else ans

