lines = []
while line = gets
    lines << line.chomp.split(' ').map(&:to_i)
end

N = lines[0][0]
K = lines[0][1]

if K > 3000000000 then

dp = []
for i in 1..N do
  low_last = 0
  high_last = 0
  num = lines[i][0]
  for j in 1..i-1 do
    if lines[i-j][0] < num and lines[i-j][0] + K >= num then
      low_last = dp[i-j-1]
      break
    end
  end
  for j in 1..i-1 do
    if lines[i-j][0] >= num and lines[i-j][0] <= num + K then
      high_last = dp[i-j-1]
      break
    end
  end
  if low_last < high_last then
    dp[i-1] = high_last + 1
  else
    dp[i-1] = low_last + 1
  end
end
    
dp_max = 0
for i in 1..N do
  if dp_max < dp[i-1] then
    dp_max = dp[i-1]
  end
end
puts dp_max
  
  
else

Inf = 3 * (10 ** 5)
  
dp = []
for i in 1..Inf do
  dp[i-1] = 0
end
  
for i in 1..N do
  num = lines[i][0]
  max_around = 0
  if num-K > 1 then
    r = num - K
  else
    r = 1
  end
  if num + K < N then
    l = num + K
  else
    l = N
  end
  for j in r..l do
    if dp[j-1] > max_around then
      max_around = dp[j-1]
    end
  end
  dp[i-1] = max_around + 1
end

dp_max = 0
for i in 1..Inf do
  if dp_max < dp[i-1] then
    dp_max = dp[i-1]
  end
end
puts dp_max + 1

end