#include <stdio.h>

int cup;
int arr[50];

int main(void) {
  int n, p;

  while (1) {
    memset(arr, 0, sizeof(arr));
    scanf("%d%d", &n, &p);

    if (n * p == 0) return 0;

    cup = p;
    int i;
    for (i = 0; arr[i % n] != p; ++i) {
      if (cup == 0) {
        cup = arr[i % n];
        arr[i % n] = 0;
      } else {
        --cup;
        ++arr[i % n];
      }
    }

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