#include <stdio.h>

int main() {
  int i, j=0, n, p, q, A[50], B[1000];
  while(1) {
    scanf("%d %d", &n, &p);
    if((n == 0) && (p == 0)) break;
    for(i=0; i<n; i++) {
      A[i] = 0;
    }
    i=0;
    q=p;
    while(1) {
      if(A[i] == q) break;
      if(p == 0) {
	p = A[i];
	A[i] = 0;
      } else  {
	p--;
	A[i]++;
      }
      ++i;
      if(i == n) i = 0;
    }
    B[j] = i;
    j++;
  }
  for(i=0; i<j; i++) {
    printf("%d\n",B[i]);
  }
  return 0;
}
