let () =
    let main () =
        let n = Scanf.scanf "%d" (fun n -> n) in
        let a = Array.init n (fun _ -> Scanf.scanf " %d" (fun a -> a)) in
        let b = Array.init n (fun _ -> Scanf.scanf " %d" (fun b -> b)) in
        let tentou a =
            let l = Array.length a in
            let rec loop i j s =
                if i >= l then s else
                    if j >= l then loop (i + 1) (i + 2) s else
                        let s = if a.(i) > a.(j) then s + 1 else s in
                        loop i (j + 1) s
            in
            loop 0 1 0
        in
        let judge even odd m =
            let evens = List.map (fun k -> (if k mod 2 = 0 then a.(k) else b.(k)), k) even in
            let odds  = List.map (fun k -> (if k mod 2 = 1 then a.(k) else b.(k)), k) odd in
            let evena = List.sort compare evens |> Array.of_list in
            let odda  = List.sort compare odds  |> Array.of_list in
            let rec loop prev i hist =
                if i = n then Some hist else
                    let (r, h) = if i mod 2 = 0 then evena.(i / 2) else odda.(i / 2) in
                    if r < prev then None else loop r (i + 1) (h :: hist)
            in
            match loop (-1) 0 [] with
            | Some hist ->
                let r = List.rev hist |> Array.of_list |> tentou in
                min m r
            | None -> m
        in
        let rec loop e o i even odd m =
            if i = n then judge even odd m else
                if e = 0 then loop e (o - 1) (i + 1) even (i :: odd) m else
                    let m = loop (e - 1) o (i + 1) (i :: even) odd m in
                    if o = 0 then m else loop e (o - 1) (i + 1) even (i :: odd) m
        in
        let e = ((n + 1) / 2) in
        let o = n - e in
        let r = loop e o 0 [] [] max_int in
        let r = if r = max_int then (-1) else r in
        Printf.printf "%d\n" r
    in
    main ()