class RMQ
  # sz は配列長
  def initialize(sz)
      @clog = 2 ** sz.bit_length
      @t = Array.new(@clog * 2, 0)
      @t[0] = :padding
  end

  # i 番目の値を変更．0-indexed
  def []=(i, x)
    j = i + @clog
    @t[j] = x
    # 上のレベルを更新
    while j > 1
      j /= 2
      u = [ @t[j * 2], @t[j * 2 + 1] ].max
      break if u <= @t[j]
      @t[j] = u
    end
  end

  # 区間 [a, b] の最大値を求める
  def query(a, b, c = @clog)
    if a > b
      return 0
    else
      side = [ (a.odd? ? @t[a + c] : 0), (b.even? ? @t[b + c] : 0) ].max
      [ side, query((a + 1) / 2, (b - 1) / 2, c / 2) ].max
    end
  end

  def inspect
    i = 1
    s = ""
    while i <= @clog
      s += @t[i, i].join(" ") + "\n"
      i *= 2
    end
    return s
  end
end

tree = RMQ.new(300_000)
 
N, K = gets.split.map(&:to_i)
N.times do
  a = gets.to_i
  left = [ 0, a - K ] .max
  right = [a + K, 299_999 ].min
  tree[a] = 1 + tree.query(left, right)
end
puts tree.query(0, 299_999)