# 解説などを参考に作成
# import sys
# sys.setrecursionlimit(10 ** 6)
# import bisect
# from collections import deque

class SegTree:
    # 参考
    # https://algo-logic.info/segment-tree/#toc_id_1
    # https://qiita.com/takayg1/items/c811bd07c21923d7ec69
    def __init__(self, elm, func, default):
        # create val
        self.layer = ((len(elm) - 1) << 1).bit_length()
        self.num = 1 << (len(elm) - 1).bit_length()
        self.func = func
        # self.tree = [default] * (2 ** self.layer - 1)
        self.tree = [default] * 2 * self.num
        self.default = default
        # update leaf
        for i in range(len(elm)):
            self.tree[self.num + i] = elm[i]
        # update nodes
        for i in range(self.num - 1, 0, -1):
            self.tree[i] = self.func(self.tree[i * 2], self.tree[i * 2 + 1])

    def update(self, i, x):
        i = self.num + i
        self.tree[i] = x
        while i > 1:
            i = i // 2
            self.tree[i] = self.func(self.tree[i * 2], self.tree[i * 2 + 1])

    def query(self, l, r):
        return self.__query(l, r, 1, 0, self.num)

    def __query(self, l, r, k, ll, rr):
        re = self.default
        if rr <= l or r <= ll:
            return re
        if l <= ll and rr <= r:
            return self.tree[k]
        vl = self.__query(l, r, k * 2, ll, ll + (rr - ll) // 2)
        rl = self.__query(l, r, k * 2 + 1, ll + (rr - ll) // 2, rr)
        return self.func(vl, rl)


# from decorator import stop_watch
# 
# 
# @stop_watch
def solve(N, K, A):
    import math
    dp = [0] * (max(A) + 1)
    st = SegTree(dp, lambda x, y: max(x, y), -(math.inf))
    for a in A:
        # print(st.query(a - K, a + K + 1))
        st.update(a, st.query(a - K, a + K + 1) + 1)
    print(st.query(0, max(A) + 1))


if __name__ == '__main__':
    N, K = map(int, input().split())
    A = [int(input()) for _ in range(N)]
    solve(N, K, A)

    # # test
    # from random import randint
    # from func import random_str
    # 
    # N, K = 300000, 300000
    # A = [i for i in range(1, N + 1)]
    # print(N, K)
    # print(A)
    # print()
    # solve(N, K, A)
