#include <bits/stdc++.h> 
using namespace std;
#define int long long
#define all(a)  (a).begin(),(a).end()
#define rall(a) (a).rbegin(), (a).rend()
#define call(a) (a).cbegin(), (a).cend()
#define pb push_back
#define pf push_front
#define eb emplace_back
#define ef emplace_front
#define mp make_pair
#define mt make_tuple
#define fs first
#define se second
#define loop(i,a,b) for(int i=(a);i<ull(b);i++)
#define rloop(i,a,b) for (int i=(b)-1;i>=(a);i--)
#define rep(i,n) for(int i=0;i<(n);i++)
#define rrep(i,n) for(int i=(n)-1;i>=0;i--)
#define iter(i,c) for(auto i=(c).begin(); i!=(c).end(); ++i)
#define riter(i,c) for(auto i=(c).rbegin(); i!=(c).rend(); ++i)
#define set(a,c) memset(a,c,sizeof a)
#define clr(a) memset(a,0,sizeof a)
#define debug(x) cout<<#x<<": "<<x<<endl
#define in scanf
#define out printf
#define f(i,j,k) fill(i[0],i[0]+j*j,k)
#define p(p) cout<<(p)<<endl;
#define exit(s,e) ((s).find(e)!=(s).end())
#define gcd(a,b) __gcd(a,b)
#define np(v) next_permutation(all(v))
#define pp(v) prev_permutation(all(v))
#define SORT(a) stable_sort(all(a))
#define RSORT(a) stable_sort(all(a),greater<int>())
#define MIN(a,b) (a>b?b:a)
#define MAX(a,b) (a>b?a:b)
#define INFILE() freopen("in0.txt","r",stdin)
#define OUTFILE() freopen("out0.txt","w",stdout)
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef vector<vb> vvb;
typedef pair<int, int> pii;
typedef pair<char, char> pcc;
typedef pair<char, int> pci;
typedef long long ll;
typedef unsigned long long ull;
const double eps = 1e-14;
const double pi  = 2*acos(0.0);
const double inf = INT_MAX/3;
int lcm(int a, int b) {return a*b/__gcd(a,b);}
bool is_leapyear(int y){return y%4==0&&(y%100!=0||y%400==0);}
int lis(int n,vi a) {
	int l[100000],length=1;l[0] = a[0];
	rep(i,n){
		if(l[length-1]<a[i])l[length++]=a[i];
		else *lower_bound(l,l+length, a[i])=a[i];
	}
	return length;
}
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
int dfs(int x, int y) {
    // (x, y) ????????????????????????????????????
    // ??¨???4??????????????????
    for(int r = 0; r < 4; r++) {
        int nx = x + dx[r];
        int ny = y + dy[r];
        dfs(nx, ny);
    }
}
//?´???°??????
int isPrime(int x){
    int i;
    if(x<2) return 0;
    else if (x == 2 ) return 1;
    if(x%2==0) return 0;
    for(i=3;i*i<=x;i+=2){
        if(x%i==0) return 0;
    }
    return 1;
}

//Union-find tree
class DisjointSet{
    public:
        vector<int> rank, p;
        DisjointSet(){}
        DisjointSet(int size){
            rank.resize(size,0);
            p.resize(size,0);
            for(int i=0; i<size; i++) makeSet(i);
        }
        void makeSet(int x){
            p[x] = x;
            rank[x] = 0;
        }
        bool same(int x, int y){
            return findSet(x) == findSet(y);
        }
        void unite(int x, int y){
            link(findSet(x), findSet(y));
        }
        void link(int x, int y){
            if(rank[x]>rank[y]){
                p[y] = x;
            } else {
                p[x] = y;
                if(rank[x]==rank[y]) {
                    rank[y]++;
                }
            }
        }
        int findSet(int x){
            if(x!=p[x]){
                p[x] = findSet(p[x]);
            }
            return p[x];
        }
};

//??????
class Point {
    public:
        double x,y;
        Point (double x=0, double y=0):x(x), y(y){}
        Point operator + (Point p) {return Point(x+ p.x,y+p.y);}
        Point operator - (Point p) {return Point(x- p.x,y-p.y);}
        Point operator * (double a) {return Point(a*x,a*y);}
        Point operator / (double a) {return Point(x/a, y/a);}
        double abs() {return sqrt(norm());}
        double norm() {return x*x+y*y;}

        bool operator < (const Point &p) const {
            return x != p.x ? x<p.x : y< p.y;
        }

        bool operator == (const Point &p) const{
            return fabs(x-p.x) < eps && fabs ( y-p.y) < eps; 
        }
};
typedef Point Vector;

// struct Point { double x, y; };
// typedef Point Vector;
// struct Segment { Point p1,p2;};
// typedef Segment Line;
// class Circle {
//     public:
//         Point c;
//         double r;
//         Circle(Point c = Point(), double r = 0.0): c(c), r(r){}
// };

// typedef vector<Point> Polygon;


double dot(Vector a, Vector b){
    return a.x* b.x + a.y * b.y;
}
double cross(Vector a, Vector b){
    return a.x* b.y - a.y * b.x;
}

signed main(){
    int n,q;
    while(cin >> n >> q&&n+q!=0){
        int m,ans=-1;
        vi a(n,0); m=q;
        while(ans==-1){
            rep(i,n){
                if(q!=0){
                    q--;
                    a[i]++;
                }
                else if(q==0){
                    q=a[i];
                    a[i]=0;
                }
                if(a[i]==m) ans=i;
            }
        }
        cout << ans << endl;
        }
}

Measured memory_bytes: 3096