import sys     
import math as mt
import bisect
input=sys.stdin.readline
#t=int(input())
t=1
def ncr_util():
    inv[0]=inv[1]=1
    fact[0]=fact[1]=1
    for i in range(2,300001):
        inv[i]=(inv[i%p]*(p-p//i))%p
    for i in range(1,300001):
        inv[i]=(inv[i-1]*inv[i])%p
        fact[i]=(fact[i-1]*i)%p
def solve():
    dp=[1]*(n)
    maxi=max(l[:])
    mini=min(l[:])
    d={}
    for i in range(n):
        maxm=0
        for j in range(l[i],min(maxi+1,l[i]+k+1)):
            if d.get(j,-1)!=-1:
                maxm=max(maxm,dp[d[j]])
        for j in range(max(l[i]-k,0),l[i]+1):
            if d.get(j,-1)!=-1:
                maxm=max(maxm,dp[d[j]])
            
        d[l[i]]=i
        dp[i]+=maxm
    return dp[n-1]            
       
for _ in range(t):
    #n=int(input())
    n,k=(map(int,input().split()))
    l=[]
    for i in range(n):
        l.append(int(input()))
    #n1=n
    #a=int(input())
    #b=int(input())
    #a,b,c,r=map(int,input().split())
    #x2,y2=map(int,input().split())
    
    #n=int(input())
    #s=input()
    #s1=input()
    #p=input()
    #l=list(map(int,input().split()))
    #l2=list(map(int,input().split()))
    #l=str(n)
    #l.sort(reverse=True)
    #l2.sort(reverse=True)
    #l1.sort(reverse=True)
    print(solve())