str = gets.chomp
while str != "0 0"
  n,p = str.split.map(&:to_i)
  #print("n=",n," p=",p,"\n")
  array = Array.new(n,0)
  i = 0
  index = 0
  loop do
    index = 0 if index == n
    #???????°???????????????¨???
    if p > 0
      #???????
      if p == 1
        flag = true
        array.size.times do |i|
          if i != index && array[i] != 0
            flag = false
            break
          end
        end
        #??????
        if flag
          puts index
          str = gets.chomp
          break
        end
      end
      array[index] += 1
      p -= 1
    #?°???????????????§???
    elsif p == 0
      p = array[index]
      array[index] = 0
    end
    index += 1
  end
end
