#include <stdio.h>

int main() {
  int n, p;
  int i, j, num;

  int mayor[50];
  
  while(1) {
    i = 0;

    scanf("%d %d", &n, &p);
    if(n == 0 && p == 0) { return 0; }

    for(j = 0; j < n; j ++) {
      mayor[j] = 0;
    }

    while(1) {
      if(p > 0) {

	mayor[i%n] ++;
	p --;
      }
      else if(p == 0) {
	p = mayor[i%n];
	mayor[i%n] = 0;
      }

      if(p == 0){
	num = 0;

	for(j = 0; j < n; j ++) {
	  if(mayor[j] != 0) {
	    num ++;
	  }
	}

	if(num == 1) {
	  printf("%d\n", i%n);

	  break;
	}
      }
      
      i ++;
    }
  }

  return 0;
}