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


seg = [0] * (1<<23)
def set_value(pos, val):
    pos += 1 << 22
    seg[pos] = val
    while (pos := pos//2) > 0:
        seg[pos] = max(seg[pos*2], seg[pos*2+1])
     

def get_max(ql, qr, sl=0, sr=1<<22, pos=1):
    if qr<=sl or sr<=ql:
        return 0
    if ql<=sl and sr<=qr:
        return seg[pos]
    sm = (sl+sr) // 2
    lmax = get_max(ql, qr, sl, sm, pos*2)
    rmax = get_max(ql, qr, sm, sr, pos*2+1)
    return max(lmax, rmax)

dp = [0] * (400000)
for i in range(1, n+1):
    a = int(input())
    l = a - k
    r = a + k + 1
    m = get_max(l, r)
    dp[i] = m + 1
    set_value(a, dp[i])

print(dp[n])