#include <bits/stdc++.h>
using namespace std;

bool solve(){
    int n, p, r;
    cin >> n >> p;
    if(n == 0) return false;
    vector<int> a(n);
    r = p;
    for(int i=0;;i=(i+1)%n){
        if(r>0){
            a[i]++;
            r--;
        }else{
            r += a[i];
            a[i] = 0;
        }
        if(a[i] == p){
            cout << i << endl;
            break;
        }
    }
    return true;
}

int main(){
    while(solve());
    return 0;
}
