#include<stdio.h>

int main(){
  int i, n, p, q, win, data[50];

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

    for(i=0; i<n; i++)
      data[i] = 0;

    i = 0;
    q = p;
    while(1){
      if(q == 0){
        q = data[i];
        data[i] = 0;
      }else{
        data[i]++;
        q--;
      }

      if(data[i] == p && q == 0){
        win = i;
        break;
      }

      if(i == n-1) i = 0;
      else i++;
    }

    printf("%d\n", win);
  }

  return 0;
}