#include <stdio.h>

int main(void){
    int n, p;

    while(1){
        scanf("%d %d", &n, &p);
        if(n == 0 && p == 0){
            break;
        }

        int candidate[n];

        int i;
        for(i = 0; i < n; i++){
            candidate[i] = 0;
        }

        int remain = p;
        int j = 0;
        while(1){
            if(remain != 0){
                candidate[j]++;
                remain--;
                if(candidate[j] == p){
                    break;
                }
            }

            else{
                remain = candidate[j];
                candidate[j] = 0;
            }
            if(j != n-1){
                j++;
            }
            else{
                j = 0;
            }
        
        }
        printf("%d\n", j);
    }

    return 0;
}
