# -*- coding: utf-8 -*-
import sys
N,K=map(int, sys.stdin.readline().split())
A=[ int(sys.stdin.readline().strip()) for _ in range(N) ]
max_A=max(A)

# max_Aが処理する区間の長さ
N0 = 2**(3*10**5-1).bit_length()
data = [0]*(2*N0)
# a_k の値を x に更新
def update(k, x):
    k += N0-1
    data[k] = x
    while k >= 0:
        k = (k - 1) // 2
        data[k] = max(data[2*k+1], data[2*k+2])
# 区間[l, r)の最大値
def query(l, r):
    L = l + N0; R = r + N0
    s = float("-inf")
    while L < R:
        if R & 1:
            R -= 1
            s = max(s, data[R-1])

        if L & 1:
            s = max(s, data[L-1])
            L += 1
        L >>= 1; R >>= 1
    return s

for i,a in enumerate(A):
    update(a,query(max(a-K,1),min(a+K+1,max_A+1))+1)

print query(0,max_A+1)
