while true
	n,p = gets.split(" ").map{|e|e.to_i}
	break if n==0 && p==0

	array=Array.new(n,0)
	array[0]=1
	i=0
	cup = p-1
	while !(cup == 0 && array.count(0)==n-1)
		i+=1
		i=0 if i>=n
		if cup > 0
			array[i] += 1
			cup -= 1
		else
			cup = array[i]
			array[i]=0
		end
		#p array
		#p cup
	end
	p i
end