#include <stdio.h>
#include <string.h>

int main(void)
{
    int n, p;
    int kouho[50];
    int wan;
    int step;
    
    while (1){
        memset(kouho, 0, sizeof(kouho));
        
        scanf("%d%d", &n, &p);
        if (n == 0 && p == 0){
            break;
        }
        
        wan = p;
        step = 0;
        while (1){
            if (wan > 0){
                kouho[step]++;
                wan--;
                if (kouho[step] == p){
                    break;
                }
            }
            else {
                wan += kouho[step];
                kouho[step] = 0;
            }
            step = (step + 1) % n;
        }
        printf("%d\n", step);
    }
    return (0);
}

