#include<stdio.h>
#include<iostream>
#include<string.h>
using namespace std;
typedef long long ll;
#define debug(x) cerr << __LINE__ << " : " << #x << " = " << (x) << endl;
#define REP(i,n) for(int i=0;i<(int)(n);i++)
#define FOR(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define FORR(i,a,b) for(int i=(int)(b)-1;i>=(int)(a);i--)
#define CHMIN(a,b) (a) = min((a),(b))
#define CHMAX(a,b) (a) = max((a),(b))

int main()
{
    int n,p;
    while(1==1)
    {
        scanf("%d %d\n",&n,&p);
        if(n==0&&p==0)return 0;
        int ko[55]={};
        int zan=p;
        int poi=0;
        int judge=0;
        while(judge==0)
        {
            for(int i=0;i<n;i++)ko[i]+=zan/n;
            zan-=(zan/n)*n;
            while(zan>0)
            {
                ko[poi]++;
                if(ko[poi]==p)
                {
                    printf("%d\n",poi);
                    judge=1;
                    break;
                }
                zan--;
                poi++;
                if(poi>=n)poi-=n;
            }
            if(judge==1)break;
            while(zan==0)
            {
                if(ko[poi]>0)
                {
                    zan=ko[poi];
                    ko[poi]=0;
                }
                poi++;
                if(poi>=n)poi-=n;
            }
        }
    }
    return 0;
}

#include <iostream>
#include <vector>
using namespace std;

int main(){
	cin.tie(0);
    ios::sync_with_stdio(false);
	vector<int> ansvec;

	for(;;){
		int n, p;
		cin >> n >> p;
		if (n == 0) break;
		
		int bowlp = p;
		int turn = 0;
		int mayors[50]{0};
		for(;;){
			if (bowlp == 1 && mayors[turn] == p - 1) break;
			else if (bowlp == 0){
				bowlp += mayors[turn];
				mayors[turn] = 0;
			}
			else{
				mayors[turn]++;
				bowlp--;
			}

			if (turn == n - 1) turn = 0;
			else turn++;
		}
		ansvec.push_back(turn);
	}

	for (int ans : ansvec){
		cout << ans << endl;
	}
	return 0;
}