Scanf.scanf "%d" (fun n ->
    let p = Array.init n (fun _ -> Scanf.scanf " %d" (fun p -> p - 1)) in

    let swap a =
        let c = p.(a) in
        p.(a) <- p.(a + 1);
        p.(a + 1) <- c
    in

    let rec loop i acc =
        if i = n - 1 then acc else
            if p.(i) = i then (
                swap i;
                loop (i + 1) (acc + 1)
            ) else if i = n - 2 && p.(i + 1) = i + 1 then (
                swap i;
                loop (i + 1) (acc + 1)
            ) else loop (i + 1) acc
    in
    loop 0 0 |> Printf.printf "%d\n"
)