module type Segtree = sig
    type s
    type t

    val create   : int -> t
    val of_array : s array -> t
    val set      : t -> int -> s -> unit
    val get      : t -> int -> s
    val prod     : t -> int -> int -> s
    val all_prod : t -> s
end

module type SegtreeParam = sig
    type t

    val op : t -> t -> t
    val e  : t
end 

module Segtree = struct
    module Make(STP: SegtreeParam) : Segtree with type s = STP.t = struct
        type t = int * int * int * STP.t array
        type s = STP.t

        let ceil_pow2 n =
            let rec loop x =
                if 1 lsl x < n then loop (x + 1) else x
            in
            loop 0

        let update d k =
            d.(k) <- STP.op d.(2 * k) d.(2 * k + 1)

        let of_array v =
            let n = Array.length v in
            let log = ceil_pow2 n in
            let size = 1 lsl log in
            let d = Array.make (2 * size) STP.e in
            for i = 0 to n - 1 do d.(size + i) <- v.(i) done;
            for i = size - 1 downto 1 do update d i done;
            n, size, log, d

        let create n =
            of_array (Array.make n STP.e)

        let set (n, size, log, d) p x =
            let p = p + size in
            d.(p) <- x;
            for i = 1 to log do update d (p lsr i) done

        let get (_, size, _, d) p = d.(p + size)

        let prod (n, size, log, d) l r =
            let rec loop l r sml smr =
                if l >= r then STP.op sml smr else
                    let sml, l = if l land 1 = 0 then sml, l else STP.op sml d.(l),     l + 1 in
                    let smr, r = if r land 1 = 0 then smr, r else STP.op d.(r - 1) smr, r - 1 in
                    loop (l lsr 1) (r lsr 1) sml smr
            in
            loop (l + size) (r + size) STP.e STP.e

        let all_prod (_, _, _, d) = d.(1)
    end
end;;
Scanf.scanf "%d %d" (fun n k ->
    let module ST = Segtree.Make (struct type t = int let op = max let e = 0 end) in

    let seg = ST.create 600001 in
    for i = 0 to n - 1 do
        Scanf.scanf " %d" (fun a ->
            let l = max 0 (a - k) in
            let r = min 600000 (a + k + 1) in
            let v = ST.prod seg l r in
            ST.set seg a (v + 1)
        )
    done;
    Printf.printf "%d\n" @@ ST.all_prod seg
)