### main

loop do
  n, pn = gets.split.map(&:to_i)
  break if (n | pn) == 0

  pls = n.times.map{0}
  zeros = n
  bwl = pn

  id = 0

  loop do
    if bwl > 0
      pls[id] += 1
      bwl -= 1
      zeros -= 1 if pls[id] == 1
    else
      zeros += 1 if pls[id] > 0
      bwl = pls[id]
      pls[id] = 0
    end

    break if bwl == 0 && zeros == n - 1

    id = (id + 1) % n
  end

  puts id
end