package main

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

func configure(scanner *bufio.Scanner) {
	scanner.Split(bufio.ScanWords)
	scanner.Buffer(make([]byte, 1000005), 1000005)
}
func getNextString(scanner *bufio.Scanner) string {
	scanned := scanner.Scan()
	if !scanned {
		panic("scan failed")
	}
	return scanner.Text()
}
func getNextInt(scanner *bufio.Scanner) int {
	i, _ := strconv.Atoi(getNextString(scanner))
	return i
}
func getNextInt64(scanner *bufio.Scanner) int64 {
	i, _ := strconv.ParseInt(getNextString(scanner), 10, 64)
	return i
}
func getNextFloat64(scanner *bufio.Scanner) float64 {
	i, _ := strconv.ParseFloat(getNextString(scanner), 64)
	return i
}
func main() {
	fp := os.Stdin
	wfp := os.Stdout
	extra := 0
	if os.Getenv("I") == "IronMan" {
		fp, _ = os.Open(os.Getenv("END_GAME"))
		extra = 100
	}
	scanner := bufio.NewScanner(fp)
	configure(scanner)
	writer := bufio.NewWriter(wfp)
	defer func() {
		r := recover()
		if r != nil {
			fmt.Fprintln(writer, r)
		}
		writer.Flush()
	}()
	solve(scanner, writer)
	for i := 0; i < extra; i++ {
		fmt.Fprintln(writer, "-----------------------------------")
		solve(scanner, writer)
	}
}
func solve(scanner *bufio.Scanner, writer *bufio.Writer) {
	n := getNextInt(scanner)
	k := getNextInt(scanner)
	aa := make([]int, n)
	for i := 0; i < n; i++ {
		aa[i] = getNextInt(scanner)
	}
	const Mx = 300001
	ss := make([]SInterface, Mx)
	for i := 0; i < Mx; i++ {
		ss[i] = E()
	}
	seg := NewSegTreeWithData(ss, E)
	for i := 0; i < n; i++ {
		x := seg.Prod(max(0, aa[i]-k), min(Mx, aa[i]+k+1)).(*S).x
		seg.Set(aa[i], &S{x: x + 1})
	}
	fmt.Fprintln(writer, seg.AllProd().(*S).x)
}
func max(a, b int) int {
	if a < b {
		return b
	}
	return a
}
func min(a, b int) int {
	return -max(-a, -b)
}

type S struct {
	x int
}

func (s *S) Op(l, r SInterface) SInterface {
	ll, rr := l.(*S), r.(*S)
	if ll.x > rr.x {
		s.x = ll.x
	} else {
		s.x = rr.x
	}
	return s
}
func (s *S) E() {
	s.x = 0
}
func E() SInterface {
	var s S
	s.E()
	return &s
}

// SInterface Type S interface
type SInterface interface {
	Op(SInterface, SInterface) SInterface
	E()
}

// SegTree is the data structure for monoids
type SegTree struct {
	n, size, log int
	d            []SInterface
	e            func() SInterface
	sml, smr     SInterface
}

// NewSegTree Constructor
func NewSegTree(n int, e func() SInterface) *SegTree {
	a := make([]SInterface, n)
	for i := 0; i < n; i++ {
		a[i] = e()
	}
	return NewSegTreeWithData(a, e)
}

// NewSegTreeWithData Constructor
func NewSegTreeWithData(a []SInterface, e func() SInterface) *SegTree {
	n := len(a)
	log := 0
	for i := n; i > 0; i >>= 1 {
		log++
	}
	size := 1 << log
	d := make([]SInterface, size<<1)
	for i := 0; i < size<<1; i++ {
		d[i] = e()
	}
	for i := 0; i < n; i++ {
		d[i+size] = a[i]
	}
	s := SegTree{d: d, e: e, n: n, size: size, log: log, sml: e(), smr: e()}
	for i := size - 1; i > 0; i-- {
		s.update(i)
	}
	return &s
}

// Set assigns x to a[p]
func (s *SegTree) Set(p int, x SInterface) {
	p += s.size
	s.d[p] = x
	for i := 1; i <= s.log; i++ {
		s.update(p >> i)
	}
}

// Get returns a[p]
func (s *SegTree) Get(p int) SInterface {
	return s.d[p+s.size]
}

// Prod returns op(a[l], ..., a[r - 1]), assuming the properties of the monoid. It returns e() if l = r.
func (s *SegTree) Prod(l, r int) SInterface {
	s.sml.E()
	s.smr.E()
	l += s.size
	r += s.size
	for l < r {
		if l&1 == 1 {
			s.sml.Op(s.sml, s.d[l])
			l++
		}
		if r&1 == 1 {
			r--
			s.smr.Op(s.d[r], s.smr)
		}
		l >>= 1
		r >>= 1
	}
	return s.sml.Op(s.sml, s.smr)
}

// AllProd returns op(a[0], ..., a[n - 1]), assuming the properties of the monoid. It returns e() if n = 0.
func (s *SegTree) AllProd() SInterface {
	return s.d[1]
}

// MaxRight returns an index r that satisfies both of the following.
// r = l or f(op(a[l], a[l + 1], ..., a[r - 1])) = true
// r = n or f(op(a[l], a[l + 1], ..., a[r])) = false
func (s *SegTree) MaxRight(l int, f func(x SInterface) bool) int {
	if l == s.n {
		return s.n
	}
	l += s.size
	s.sml.E()
	s.smr.E()
	for {
		for l&1 == 0 {
			l >>= 1
		}
		if !f(s.smr.Op(s.sml, s.d[l])) {
			for l < s.size {
				l <<= 1
				if f(s.smr.Op(s.sml, s.d[l])) {
					s.sml, s.smr = s.smr, s.sml
					l++
				}
			}
			return l - s.size
		}
		s.sml.Op(s.sml, s.d[l])
		l++
		if l&-l == l {
			break
		}
	}
	return s.n
}

// MinLeft returns an index l that satisfies both of the following.
// l = r or f(op(a[l], a[l + 1], ..., a[r - 1])) = true
// l = 0 or f(op(a[l - 1], a[l + 1], ..., a[r - 1])) = false
func (s *SegTree) MinLeft(r int, f func(x SInterface) bool) int {
	if r == 0 {
		return 0
	}
	r += s.size
	s.sml.E()
	s.smr.E()
	for {
		r--
		for r > 1 && r&1 == 1 {
			r >>= 1
		}
		if !f(s.smr.Op(s.sml, s.d[r])) {
			for r < s.size {
				r = r<<1 + 1
				if f(s.smr.Op(s.sml, s.d[r])) {
					s.sml, s.smr = s.smr, s.sml
					r--
				}
			}
			return r + 1 - s.size
		}
		s.sml.Op(s.sml, s.d[r])
		if r&-r == r {
			break
		}
	}
	return 0
}
func (s *SegTree) update(k int) {
	s.d[k].Op(s.d[k<<1], s.d[k<<1+1])
}


Measured memory_bytes: 40724