n, k, *al = map(int, open(0).read().split())
d = [0] * 300000
for a in al:
    l = max(0, a-k)
    r = min(a+k, 300000)
    m = 0
    for i in range(l, r+1):
        m = max(m, d[i])
    d[a] = max(d[a], m+1)
print(max(d))