import sys
input = sys.stdin.readline
n, k = map(int,input().split())
A = [int(input()) for i in range(n)]

from atcoder.segtree import SegTree

l = 3*10**5 + 10
S = SegTree(max, 0, l)
for i in range(n):
    S.set(A[i], S.prod(max(0, A[i]-k), min(l, A[i]+k+1)) + 1)

print(S.all_prod())