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