loop {
	n, s0 = gets.split.map &:to_i
	break if n == 0
	s = s0
	a = [0] * n
	i = 0
	
	loop {
		k = s / n
		a.map!{|x| x + k}
		(s % n).times{
			a[i] += 1
			i = (i+1)%n
		}
		break if a[(i-1)%n] == s0
		i = (i+1)%n until a[i] > 0
		s = a[i]
		a[i] = 0
		i = (i+1)%n
	}
	p (i-1)%n
}