
from collections import defaultdict
from bisect import bisect
n, k = list(map(int, input().split()))
al = [0] * n
for i in range(n):
    al[i] = int(input())

d = defaultdict(lambda: 0)
d[al[0]] = 1
for a in al[1:]:
    m = 0
    for i in range(max(0, a-k), a+k+1):
        m = max(m, d[i])
    d[a] = m+1
print(max(d.values()))
