Scanf.scanf "%d %d" (fun n m ->
    let a = Array.init n (fun _ -> Scanf.scanf " %d" (fun a -> a - 1)) in
    let hist = Array.make n 0 in
    let mask = Array.make n 0 in
    Array.iter (fun v ->
        hist.(v) <- hist.(v) + 1;
        let o = max 0 (v - hist.(v) + 1) in
        mask.(o) <- mask.(o) + 1;
    ) a;
    let rec loop i hall =
        if i < m then (
            let hall =
                Scanf.scanf " %d %d" (fun z y ->
                    let x = a.(z - 1) in let y = y - 1 in
                    a.(z - 1) <- y;

                    let o = max 0 (x - hist.(x) + 1) in
                    mask.(o) <- mask.(o) - 1;
                    hist.(x) <- hist.(x) - 1;

                    let hall = if mask.(o) = 0 then hall + 1 else hall in

                    hist.(y) <- hist.(y) + 1;
                    let o = max 0 (y - hist.(y) + 1) in
                    mask.(o) <- mask.(o) + 1;
                    
                    let hall = if mask.(o) = 1 then hall - 1 else hall in
                    Printf.printf "%d\n" hall;
                    hall
                )
            in
            loop (i + 1) hall
        )
    in
    loop 0 (Array.fold_left (fun acc v -> if v = 0 then acc + 1 else acc) 0 mask)
)