import sys
input = lambda : sys.stdin.readline().rstrip()

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

M = 300000
#nums = [int(input()) for i in range(n)]
#graph = [[] for i in range(n)]
#
#for node1 in range(n-1):
#    num1 = nums[node1]
#    for node2 in range(node1+1, n):
#        num2 = nums[node2]
#        if abs(num1-num2) <= k:
#            graph[node2].append(node1)

kosuus = [0] * (M+1)

out = 0
for i in range(n):
    num = int(input())
    min_i = max(1, num-k)
    max_i = min(M-1, num+k)
    kosuu = max(kosuus[min_i:max_i+1]) + 1
    kosuus[num] = kosuu
    out = max(kosuu, out)
     
print(out)