import sys

sys.setrecursionlimit(10**8)



class SegTree:

    def __init__(self, N, ele):

        self.num = 2**(N-1).bit_length()

        self.el = ele

        self.data = [ele]*(2*self.num)



    def calc(self, x, y):

        return max(x, y)



    def update(self, idx, x):

        idx += (self.num - 1)

        self.data[idx] = x

        while idx > 0:

            idx = (idx-1)//2

            self.data[idx] = self.calc(self.data[2*idx+1], self.data[2*idx+2])



    def query(self, l, r):

        L = l + self.num

        R = r + self.num

        res = self.el

        while L < R:

            if L & 1:

                res  = self.calc(res, self.data[L-1])

                L += 1

            if R & 1:

                R -= 1

                res = self.calc(res, self.data[R-1])

            L >>= 1

            R >>= 1

        return res

    

    def get(self, idx):

        idx += (self.num - 1)

        return self.data[idx]



n, k = list(map(int, input().split()))

A = [int(eval(input())) for _ in range(n)]

seg = SegTree(330000, 0)

max_a = 300010

for a in A:

    l = max(0, a-k)

    r = min(max_a, a+k+1)

    now = seg.query(l, r)

    seg.update(a, now+1)



print((seg.query(0, max_a)))

import sys

sys.setrecursionlimit(10**8)

input = sys.stdin.readline



class SegTree:

    def __init__(self, N, ele):

        self.num = 2**(N-1).bit_length()

        self.el = ele

        self.data = [ele]*(2*self.num)



    def calc(self, x, y):

        return max(x, y)



    def update(self, idx, x):

        idx += (self.num - 1)

        self.data[idx] = x

        while idx > 0:

            idx = (idx-1)//2

            self.data[idx] = self.calc(self.data[2*idx+1], self.data[2*idx+2])



    def query(self, l, r):

        L = l + self.num

        R = r + self.num

        res = self.el

        while L < R:

            if L & 1:

                res  = self.calc(res, self.data[L-1])

                L += 1

            if R & 1:

                R -= 1

                res = self.calc(res, self.data[R-1])

            L >>= 1

            R >>= 1

        return res

    

    def get(self, idx):

        idx += (self.num - 1)

        return self.data[idx]



n, k = list(map(int, input().split()))

A = [int(eval(input())) for _ in range(n)]

seg = SegTree(330000, 0)

max_a = 300010

for a in A:

    l = max(0, a-k)

    r = min(max_a, a+k+1)

    now = seg.query(l, r)

    seg.update(a, now+1)



print((seg.query(0, max_a)))

import sys

sys.setrecursionlimit(10**8)


class SegTree:
    def __init__(self, N, ele):
        self.num = 2 ** (N - 1).bit_length()
        self.el = ele
        self.data = [ele] * (2 * self.num)

    def calc(self, x, y):
        return max(x, y)

    def update(self, idx, x):
        idx += self.num - 1
        self.data[idx] = x
        while idx > 0:
            idx = (idx - 1) // 2
            self.data[idx] = self.calc(self.data[2 * idx + 1], self.data[2 * idx + 2])

    def query(self, l, r):
        L = l + self.num
        R = r + self.num
        res = self.el
        while L < R:
            if L & 1:
                res = self.calc(res, self.data[L - 1])
                L += 1
            if R & 1:
                R -= 1
                res = self.calc(res, self.data[R - 1])
            L >>= 1
            R >>= 1
        return res

    def get(self, idx):
        idx += self.num - 1
        return self.data[idx]


n, k = list(map(int, input().split()))
A = [int(eval(input())) for _ in range(n)]
seg = SegTree(330000, 0)
max_a = 300010
for a in A:
    l = max(0, a - k)
    r = min(max_a, a + k + 1)
    now = seg.query(l, r)
    seg.update(a, now + 1)
print((seg.query(0, max_a)))

import sys

sys.setrecursionlimit(10**8)
input = sys.stdin.readline


class SegTree:
    def __init__(self, N, ele):
        self.num = 2 ** (N - 1).bit_length()
        self.el = ele
        self.data = [ele] * (2 * self.num)

    def calc(self, x, y):
        return max(x, y)

    def update(self, idx, x):
        idx += self.num - 1
        self.data[idx] = x
        while idx > 0:
            idx = (idx - 1) // 2
            self.data[idx] = self.calc(self.data[2 * idx + 1], self.data[2 * idx + 2])

    def query(self, l, r):
        L = l + self.num
        R = r + self.num
        res = self.el
        while L < R:
            if L & 1:
                res = self.calc(res, self.data[L - 1])
                L += 1
            if R & 1:
                R -= 1
                res = self.calc(res, self.data[R - 1])
            L >>= 1
            R >>= 1
        return res

    def get(self, idx):
        idx += self.num - 1
        return self.data[idx]


n, k = list(map(int, input().split()))
A = [int(eval(input())) for _ in range(n)]
seg = SegTree(330000, 0)
max_a = 300010
for a in A:
    l = max(0, a - k)
    r = min(max_a, a + k + 1)
    now = seg.query(l, r)
    seg.update(a, now + 1)
print((seg.query(0, max_a)))

+input = sys.stdin.readline