#include<stdio.h>
#include<string.h>
int main(){
    int n, p, i, r, data[51]={}, nokori=0;
    for(;scanf("%d%d", &n, &p);){
        if( n == 0 && p == 0 ){
            break;
        }
        for( i = 0, nokori = p;; i++ ){
            if( nokori != 0 ){
                data[i] = data[i] + 1;
                nokori = nokori - 1;
            }else{
                nokori = data[i];
                data[i] = 0;
            }
            if( data[i] == p ){
                printf("%d\n", i);
                break;
            }
            if( i == n - 1 ) i = -1;
        }
        memset( data, 0, 50 );
    }
    return 0;
}