#include <stdio.h>

int main(void) {
  int n, p, count[50], t = 0, i, j;

  while (1) {
    scanf("%d %d", &n, &p);
    if (n == 0 && p == 0) break;

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

    t = p;
    i = 0;
    while (1) {
      if (t > 0) {
	count[i]++;
	t--;
      }
      else {
	t = count[i];
	count[i] = 0;
      }
      if (count[i] == p) {
        printf("%d\n", i);
	break;
      }
      i++;
      if (i == n) i = 0;
    }
  }

  return 0;
}