#include<stdio.h>
#include<math.h>

#define MAX 100

int main(void)
{
  int n,p,i,isi;
  int a[MAX];

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