until (n, p = gets.split.map(&:to_i)) == [0, 0]
  c = Array.new(n, 0)
  np = p
  i = 0
  while c[i] < p
    if np == 0 then
      np = c[i]
      c[i] = 0
    else
      c[i] += 1
      np -= 1
    end
    i += 1
    i %= n
  end
  puts i
end