
import sys
# sys.setrecursionlimit(100000)


def input():
    return sys.stdin.readline().strip()


def input_int():
    return int(input())


def input_int_list():
    return [int(i) for i in input().split()]


class SegmentTree:
    x_unit = 0
    x_f = max
    # 1-based index

    def __init__(self, n: int):
        self.n = n
        self.tree = [self.x_unit] * (n + n)

    def build(self, seq):
        for i, x in enumerate(seq, self.n):
            self.tree[i] = x
        for i in range(self.n - 1, 0, -1):
            self.tree[i] = self.x_f(self.tree[i << 1], self.tree[i << 1 | 1])

    def set_val(self, i, x):
        """value update"""
        i += self.n
        self.tree[i] = x
        while i > 1:
            i >>= 1
            self.tree[i] = self.x_f(self.tree[i << 1], self.tree[i << 1 | 1])

    def fold(self, L, R):
        """range query"""
        L += self.n
        R += self.n
        vL = vR = self.x_unit
        while L < R:
            if L & 1:
                vL = self.x_f(vL, self.tree[L])
                L += 1
            if R & 1:
                vR = self.x_f(vR, self.tree[R])
                R -= 1
            L >>= 1
            R >>= 1
        return self.x_f(vL, vR)


def main():
    n, k = input_int_list()
    segtree = SegmentTree(400000)
    for _ in range(n):
        a = input_int()

        val = segtree.fold(max(0, a - k), min(40000, a + k + 1))
        segtree.set_val(a, val + 1)

    print(segtree.tree[1])

    return


if __name__ == "__main__":
    main()
