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

s=[0]*n
a=[0]*n
for i in range(n):
    a[i]=int(input())
    for ii in range(i):
        if abs(a[i]-a[ii])<=k:
            s[i]=max(s[i],s[ii]+1)
            
print(max(s))
