class Counter
  @@max_size = 3
  def initialize(max, cond)
    @max = max
    @cond = cond
    @queue = []
    @count = 0
  end
  def run
    @queue << [1, @max, []]
    while @queue.size > 0 do
      task = @queue.shift
      from, to, nums = task
      (from..to).each do |i|
        new_nums = nums + [i]
        if new_nums.size >= @@max_size
          if new_nums.reduce{|sum, n| sum + n} == @cond
            @count += 1
          end
        else
          if i + 1 <= @max
            @queue << [i + 1, @max, new_nums]
          end
        end
      end
    end
    return @count
  end
end

lines = STDIN.read.split("\n")
lines.each do |line|
  n, x = line.split(' ').map(&:to_i)
  break if n == 0 && x == 0
  puts Counter.new(n, x).run()
end