#include <stdio.h>

int main()
{
    int n, p;

    while (scanf("%d %d", &n, &p) * n){
        int stone[64] = {0};
        int bowl = p;
        int i;

        for (i = 0; stone[i] != p; i = (i + 1) % n){
            if (bowl > 0){
                bowl--;
                stone[i]++;
            }
            else {
                bowl += stone[i];
                stone[i] = 0;
            }
        }
        printf("%d\n", i);
    }
}