#include <stdio.h>
 
int main(void) {
    int n,p;
    
    while (1) {
       scanf("%d%d", &n, &p);
       if (!n && !p) break;
       
       int player[50] = {0};
       int stone = p;
       int i;
       
       for(i = 0; player[i] != p; i = (i+1) % n)
          if(stone > 0){
          stone--;
          player[i]++;
          }
          else if(stone == 0){
          	stone = player[i];
          	player[i] = 0;
          }
       
       printf("%d\n",i);
    }
       return 0;
}