#include <stdio.h>

int have[ 50 ];

int main( void ) {
	int i, n, p, r;

	for ( ; scanf( "%d %d", &n, &p ), r = p; printf( "%d\n", i ) )
		for ( i = 0; ; i = ( i + 1 ) % n ) {
			if ( r ) {
				r--;
				have[ i ]++;
			} else {
				r = have[ i ];
				have[ i ] = 0;
			}

			if ( r == p )
				break;
		}

	return 0;
}