let popcnt x =
  let x = (x land 0x5555555555555555) + ((x lsr 1) land 0x5555555555555555) in
  let x = (x land 0x3333333333333333) + ((x lsr 2) land 0x3333333333333333) in
  let x = (x land 0x0f0f0f0f0f0f0f0f) + ((x lsr 4) land 0x0f0f0f0f0f0f0f0f) in
  let x = (x land 0x00ff00ff00ff00ff) + ((x lsr 8) land 0x00ff00ff00ff00ff) in
  let x = (x land 0x0000ffff0000ffff) + ((x lsr 16) land 0x0000ffff0000ffff) in
  (x land 0x00000000ffffffff) + ((x lsr 32) land 0x00000000ffffffff)

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) 51 inf in
  dp.(0).(0) <- 0;
  for mask = 0 to (1 lsl n) - 1 do
    let j = popcnt mask in
    for s = 0 to 50 do
      if dp.(mask).(s) < inf then begin
        for i = 0 to n - 1 do
          if mask land (1 lsl i) = 0 then begin
            let c = popcnt (((1 lsl i) - 1) land (lnot mask)) in
            let x = if i mod 2 = j mod 2 then as_.(i) else bs.(i) in
            if s <= x then
              dp.(mask lor (1 lsl i)).(x) <-
                min dp.(mask lor (1 lsl i)).(x) (c + dp.(mask).(s))
          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
