#include <stdio.h>

int
main()
{
        int n, p;
        int i;
        int nd[50], w, step;

        while (scanf("%d %d", &n, &p), (n != 0) && (p != 0)) {
                for (i = 0; i < n; i++)
                        nd[i] = 0;
                nd[n] = -1;
                w = p;
                for (step = 0; step < 1000000; step++) {
                        if (w != 0) {
                                nd[step % n]++;
                                w--;
                        } else {
                                w = nd[step % n];
                                nd[step % n] = 0;
                        }
                        if (nd[step % n] == p)
                                break;
                }
                printf("%d\n", step % n);
        }

        return 0;
}