#include <stdio.h>
#include <stdlib.h>

#define N 50

int
main (
  int   argc,
  char *argv[ ]
  )
{
  int i;

  for ( ; ; )
  {
    int d[ N ] = { };
    int n, p;
    int r;

    scanf ( "%d%d", &n, &p );
    if ( n == 0 && p == 0 )
      break ;
    
    r = p;
    for ( i = 0; ; i = ( i + 1 ) % n )
    {
      if ( r == 0 )
      {
        r = d[ i ];
        d[ i ] = 0;
      }
      else
      {
        --r;
        ++d[ i ];
      }

      if ( d[ i ] == p )
      {
        printf ( "%d\n", i );
        break ;
      }
    }
  }


  return ( EXIT_SUCCESS );
}