//Number 1159
#include <stdio.h>

int main(void)
{
  int i, n, p, stone = 0;
  int human[50] = {0};

  while(1)
    {
      scanf("%d %d", &n, &p);

      stone = p;
      if(n == 0 && p == 0)
	break;

      for(i=0; i<n; i++)
	human[i] = 0;

      while(1)
	{
	  for(i=0; i<n; i++)
	    {
	      if(stone==0)
		{
		  stone = human[i];
		  human[i] = 0;
		}
	      else
		{
		  human[i]++;
		  stone--;
		}
	      if(human[i]==p)
		break;
	    }
	  if(human[i]==p)
	    break;
	}

      printf("%d\n", i);

    }

  return 0;
}