n,k = map(int, input().split())
dp = [0] * 300000

for i in range(n):
  tmp = int(input())
  if tmp - k <= 0:
    s = 0
  else:
    s = tmp - k - 1 
  if tmp + k >= 300000:
    e = 300000
  else:
    e = tmp + k

  if tmp != 1:
  	before_max = max(dp[s:(tmp-1)])
  else:
    before_max = 0
  if tmp != 300000:
  	after_max = max(dp[tmp:e])  
  else:
    after_max = 0
  
  tmp_max = max(after_max,before_max)
  dp[tmp-1] = tmp_max + 1

ans = max(dp)
print(ans)
