def main():
    n, k = map(int, input().split())
    cnt = [0] * (n+1)
    for _ in range(n):
        a = int(input())
        m = max(cnt[max(a-k,0):min(a+k,n)+1])
        cnt[a] = m+1
    print(cnt[a])

main()