#include <stdio.h>


int n, p;
int person[51];
int count = 0;


int calc()
{
  int k1, k2, k3;
  int num = 0;
  int c = p;

  while ( 1 ) {
    if ( c == 0 ) { c = person[num]; person[num] = 0; }
    else { person[num]++; c--; }

    if ( ++num >= n ) { num = 0; }
    if ( c == 1 && is_finish(num) ) { return num; }
  }
}

int is_finish(int num)
{
  int k;

  for ( k = 0; k < n; k++ ) {
    if ( num == k ) { continue; }
    if ( person[k] ) { return 0; }
  }
  return 1;
}

int main(void)
{
  int k1;

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

    for ( k1 = 0; k1 < 51; k1++ ) { person[k1] = 0; }

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

  return 0;
}