n,p = gets.split.map(&:to_i)
ans = []
while n !=0 && p !=0
	i = 0
	tmp = p
	a = Array.new(n,0)
	while p != 0 
		if tmp != 0
			a [i] += 1
			tmp -= 1
		elsif tmp == 0 && a[i] == p
			break
		else
			tmp = a[i]
			a[i] = 0
		end
		i = i + 1
		i = 0 if i == n
	end
	ans.push(i)
	n,p = gets.split.map(&:to_i)
end
puts ans