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

int main()
{
	int n, p;
	while (cin >> n >> p, n || p) {
		int save_p = p;
		vector<int> keeps(n, 0);
		for (int i = 0; true; ++i) {
			i %= n;
			if (p) {
				++keeps[i];
				--p;
				if (keeps[i] == save_p) {
					cout << i << endl;
					break;
				}
			} else {
				p = keeps[i];
				keeps[i] = 0;
			}
		}
	}
}