while true
  n, p_ = gets.chomp.split(" ").map(&:to_i)
  break if n == 0 && p_ == 0
  cand = Array.new(n, 0)
  stone = p_
  (0...n).cycle do |i|
    if stone > 0 then
      stone -= 1
      cand[i] += 1
      if cand[i] == p_ then
        puts i
        break
      end
    else
      if cand[i] > 0 then
        stone += cand[i]
        cand[i] = 0
      end
    end
  end
end