N, K = map(int, input().split())
A = [
  int(input()) for _ in range(N)
]

lst = [0] * 300002

for i in range(N):
  a = A[i]
  min_a = max(1, a - K)
  max_a = min(300000, a + K)
  max_val = max(lst[min_a:max_a+1])
  lst[a] = max_val + 1
  
  #print(min_a, max_a)
  
print(max(lst))