answers = []

def get_answer(n, p)
  owan = p
  index = 0
  temoto = []
  n.times do
    temoto << 0
  end
  while true
    if owan == 0
      owan += temoto[index]
      temoto[index] = 0
    else
      return index if owan == 1 && temoto[index] == p -1
      owan -= 1
      temoto[index] += 1
    end
    index += 1
  end
end


while true
  array = gets.chomp.split.map(&:to_i)
  n = array[0]
  p = array[1]
  exit if n == 0 && p == 0
  answers << get_answer(n,p)
end


answers.each do |ans|
  puts ans
end