# 候補者 0..n-1 のn人
loop do
  n, stone_num = gets.chomp.split(" ").map{ |item| item.to_i }
  max_stone_nume = stone_num
  if n == 0 && stone_num == 0
    break
  end
  candidates = [0]*n
  index = 0
  loop do
    if index == candidates.length
      index = 0
    end
    if stone_num > 0
      stone_num -= 1
      candidates[index] += 1
      if candidates[index] == max_stone_nume
        puts index
        break
      end
    elsif candidates[index] > 0
      stone_num += candidates[index]
      candidates[index] = 0
    end
    index += 1
  end
end

