#include<cstdio>

using namespace std;

int main(){
	for(int n,p;scanf("%d%d",&n,&p),n;){
		int bowl=p,got[50]={};
		for(int i=0;;i=(i+1)%n){
			if(bowl>0)	got[i]++,bowl--;
			else		bowl+=got[i],got[i]=0;
			if(got[i]==p){
				printf("%d\n",i);
				break;
			}
		}
	}
	return 0;
}