class segment_tree():
    def __init__(self, N, function, b):
        #initialization
        self.n = N
        self.K = (N-1).bit_length()
        self.f = function
        self.b = b
        self.data = [b]*(1+ (1 << (self.K+1)))
        for i in range((1 << self.K)-1, 0, -1):
            self.data[i] = self.f(self.data[i << 1], self.data[i << 1 | 1])

    def update(self, k, value):
        # update a[k] = value
        k += 1 << self.K
        self.data[k] = value
        while k:
            k = k >> 1
            self.data[k] = self.f(self.data[k << 1], self.data[(k << 1) | 1])

    def query(self, L, R):
        #query [L,R)
        L += 1 << self.K
        R += 1 << self.K
        vL = self.b
        vR = self.b
        while L < R:
            if L & 1:
                vL = self.f(vL, self.data[L])
                L += 1
            if R & 1:
                R -= 1
                vR = self.f(self.data[R], vR)
            L >>= 1
            R >>= 1
        return self.f(vL, vR)


N, K = map(int, input().split())
A = [int(input()) for i in range(N)]
ans = 0
seg_tree = segment_tree(6*10**5+1, max, 0)
for i, v in enumerate(A):
    ans = max(seg_tree.query(max(0, v-K), v+K+1) + 1, 1)
    seg_tree.update(v, ans)
print(ans)
