let n = Scanf.scanf "%d" ((+) 0)
let v = Array.init n (fun _ -> Scanf.scanf " %d" ((+) 0))
let c = Array.init 2 (fun _ -> Array.init 101010 (fun i -> (0, i)))
let upd (x, i) = (x-1, i)

let () = Printf.printf "%d\n" @@ begin
  for i = 0 to n/2 - 1 do
    c.(0).(v.(2*i)) <- upd c.(0).(v.(2*i));
    c.(1).(v.(2*i+1)) <- upd c.(1).(v.(2*i+1));
  done;
  Array.sort compare c.(0);
  Array.sort compare c.(1);
  let v00, i00 = c.(0).(0) in
  let v10, i10 = c.(1).(0) in
  if i00 <> i10 then n + v00 + v10
  else min (n + v00 + fst c.(1).(1)) (n + fst c.(0).(1) + v10)
end