package main

import (
	"bufio"
	"fmt"
	"os"
)

func main() {
	N, K := ReadInt(), ReadInt()
	A := ReadInts(N)
	max := int(3 * 1e5)
	seg := MakeSegTree(max + 1)
	for _, ai := range A {
		l := Max(0, ai-K)
		r := Min(max, ai+K+1)
		v := seg.Query(l, r)
		seg.Update(ai, v+1)
	}
	fmt.Println(seg.Query(0, max+1))
}

func Min(xs ...int) int {
	min := xs[0]
	for _, x := range xs[1:] {
		if min > x {
			min = x
		}
	}
	return min
}

// Segment Tree for Range Maximum Query (RMQ)
type SegTree []int

func MakeSegTree(n_ int) SegTree {
	n := 1
	for n < n_ {
		n <<= 1
	}
	return make([]int, n*2)
}
func (t SegTree) Update(i, x int) {
	i += len(t) >> 1
	t[i] = x
	for i > 1 {
		i >>= 1
		t[i] = Max(t[i*2], t[i*2+1])
	}
}
func (t SegTree) Query(a, b int) int {
	return t.queryRecur(a, b, 1, 0, len(t)>>1)
}
func (t SegTree) queryRecur(a, b, k, l, r int) int {
	if b <= l || r <= a {
		return 0
	}
	if a <= l && r <= b {
		return t[k]
	}
	return Max(
		t.queryRecur(a, b, k*2, l, (l+r)>>1),
		t.queryRecur(a, b, k*2+1, (l+r)>>1, r),
	)
}

func Max(xs ...int) int {
	max := xs[0]
	for _, x := range xs[1:] {
		if max < x {
			max = x
		}
	}
	return max
}

var reader = bufio.NewReader(os.Stdin)

func Scan(a ...interface{}) {
	if _, err := fmt.Fscan(reader, a...); err != nil {
		panic(err)
	}
}
func ReadInt() (i int)       { Scan(&i); return }
func ReadString() (s string) { Scan(&s); return }
func ReadInts(n int) (a []int) {
	for i := 0; i < n; i++ {
		a = append(a, ReadInt())
	}
	return
}
