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

s=[1]*n
t=[[] for i in range(n+1)]
a=[0]*n
for i in range(n):
    a[i]=int(input())
    ast=max(a[i]-k,0)
    aed=min(a[i]+k,n)
    for ai in range(ast,aed+1):
        t[ai].append(i)
    
for i in range(n):
    for ti in t[a[i]]:
        if ti<i:
            s[i]=max(s[i],s[ti]+1)
            
print(max(s))
