#include <stdio.h>

/** Application main entry point. */
int main (
  int     argc,
  char  * argv[ ]
  )
{
  for ( ; ; )
  {
    int cup, ctr;
    int psn[ 50 ] = { 0 };
    int n, p;

    scanf ( "%d%d", &n, &p );
    if ( !( n | p ) ) break ;

    cup = p;
    for ( ctr = 0; psn[ ctr ] != p; ctr = ( ctr + 1 ) % n )
    {
      if ( cup )
      {
        ++psn[ ctr ];
        --cup;
      }
      else
      {
        cup = psn[ ctr ];
        psn[ ctr ] = 0;
      }
    }

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

  return ( 0 );
}