import sys

input = sys.stdin.buffer.readline

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

max_n = 300000
num = 1 << ((max_n - 1).bit_length())
SEG = [0] * (2 * num)

func = max
ele = 0


def update(idx, val):
    idx += num
    SEG[idx] = val
    for i in reversed(range(1, num)):
        SEG[i] = func(SEG[2 * i], SEG[2 * i + 1])


def query(left, right):
    res_left = ele
    res_right = ele
    left += num
    right += num
    while left < right:
        if left & 1:
            res_left = func(res_left, SEG[left])
            left += 1
        if right & 1:
            right -= 1
            res_right = func(SEG[right], res_right)
        left //= 2
        right //= 2
    return func(res_left, res_right)


for _ in range(n):
    val = int(input())
    # print("range", max(0, val - k), min(max_n + 1, val + k + 1) - 1)
    temp = query(max(0, val - k), min(max_n + 1, val + k + 1))
    # print(temp)
    temp += 1
    update(val, temp)
    # print(val, temp)
    # print(SEG[num : num + 12])

print(SEG[1])

