#include <iostream>
#include <algorithm>
#include <cstring>
using namespace std;

int main(){

  int n, p;

  while(cin >> n >> p, n|p){
    int kouho[55];
    memset(kouho, 0, sizeof(kouho));
    int i = 0;
    int full = p;
    while(1){
      if(i == n) i = 0;
      if(p != 0){
        kouho[i]++;
        p--;
        if(kouho[i] == full) break;
      }else{
        p = kouho[i];
        kouho[i] = 0;
      }
      i++;
    }
    cout << i << endl;
  }
  return 0;
}
