#include <stdio.h>
#define ll long long
#define rep(i,l,r)for(ll i=l;i<r;i++)

ll f(ll n,ll p){
	ll cnt=p;
	ll a[100]={};
	while(1){
		for(ll crr=0;crr<n;crr++){
			if(cnt==0){
				cnt+=a[crr];
				a[crr]=0;
			}else{
				cnt--;
				a[crr]++;
				if(a[crr]==p)return crr;
			}
		}
	}
}

int main(){
	ll n,p;
	while(scanf("%lld%lld",&n,&p),n){
		printf("%lld\n",f(n,p));
	}
}

