#include <iostream>
#include <string.h>

using namespace std;

int main()
{
	int n,p;
	int stone[50];
	
	cin>> n >> p;
	
	while ( n+p > 0)
	{
		int bowl = p;
		memset(stone,0,sizeof(stone));
		for (int i=0;i<1000000;++i)
		{
			if (stone[i % n] == p) 
			{
				cout << (i%n) << endl;
				break;
			}
			
			if (bowl > 0) 
			{
				++stone[i%n];
				--bowl;
			}
			else if (stone[i%n] > 0)
			{
				bowl = stone[i%n];
				stone[i%n] = 0;
			}
			
		}
		
		cin>> n >> p;
	}
}