#include <iostream>
#include <vector>
using namespace std;
int main(void){
  int n,p;
  while(cin>>n>>p,n||p){
    vector<int> v(n);
    for(int i=0,x=p;;i=(i+1)%n){
      if(x){
        --x;++v[i];
        if(v[i]==p){cout<<i<<endl;break;}
      }else{
        x=v[i];v[i]=0;
      }
    }
  }
  return 0;
}