import sys
import bisect
from functools import lru_cache
from collections import defaultdict
inf = float('inf')
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10**6)
def input(): return sys.stdin.readline().rstrip()
def read():
  return int(readline())
def reads():
  return map(int, readline().split())

N,K=reads()
start,end=0,0
former=0
import math
maxval=0
ls=[]
sortls=[]
maxls=[1 for i in range(N)]
selectls=[0 for i in range(300000)]
for i in range(N):
    a=read()
    a-=1
    sls=selectls[a]
    maxls[i]=sls+1
    mi=max(0,a-K)
    ma=min(N-1,a+K)
    for l in range(mi,ma+1):
        selectls[l]=max(selectls[l],maxls[i])
print(max(maxls))
