n,k = map(int,input().split())
a=[]
b=[1]*n
for i in range(n):
    a.append(int(input()))
    
for i in range(n):
    for j in range(i+1, n):
        if abs(a[j]-a[i]) <= k:
            b[j] = max(b[j],b[i]+1)
print(max(b))