#include <stdio.h>
int main()
{
  int i=0, l,  p, q, j=0;
  int d[50], dd[50];

  for ( i = 0; i < 50; i++)
    {
      dd[i] = 0;
    }
  while(1)
    {
      for ( i = 0; i < 50; i++)
	{
	  d[i] = 0;
	}   
      scanf("%d %d", &l, &p);
      if( l == 0 && p == 0 ) break;
      q = p;
      while( d[i] != q )
	{
     	  if ( i >= l ) i = 0;
	  if ( p > 0 )
	    {
	      d[i] += 1;
	      p--;
	      if ( d[i] == q && p == 0)
		{
		  dd[j] = i;
		  j++;
		  break;
		}  
	    }
	  else if ( p == 0 )
	    {
	      p = d[i];
	      d[i] = 0;
	    }
	  i++;
	}
    }
  for ( i = 0; i < j; i++)
    {
      printf("%d", dd[i]);
      printf("\n");
    }
  return 0;
}