#include <cstdio>
int tree[1<<23];
int n,k, ans;
inline void init_tree(){
for(int i=n; i<2*n; ++i){
tree[i]=1;
}
for(int i=n-1; i; --i){
int j=i<<1;
tree[i]=tree[j]+tree[j|1];
}
return;
}
int find_kth(int k, int v=1){
if(v>=n){
return v-n+1;
}
int left=v<<1, left_value=tree[left];
if(left_value>=k){
return find_kth(k, left);
}
return find_kth(k-left_value, left|1);
}
void decrement(int pos){
pos+=n-1;
while(pos){
--tree[pos];
pos>>=1;
}
}
int main(){
scanf("%d%d",&n,&k);
init_tree();
int k2=k-2;
int cur=1;
int shift=find_kth(1);
for(int i=1; i<=n; ++i){
cur=1+(cur+k2)%(n-i+1);
int x=find_kth(cur);
int real_x=(x-shift+n)%n+1;
decrement(x);
int y=real_x-i;
int mask=y>>31;
ans^=(y+mask)^mask;
}
printf("%d",ans);
return 0;
}
I2luY2x1ZGUgPGNzdGRpbz4KCmludCB0cmVlWzE8PDIzXTsKaW50IG4saywgYW5zOwoKaW5saW5lIHZvaWQgaW5pdF90cmVlKCl7CiAgICBmb3IoaW50IGk9bjsgaTwyKm47ICsraSl7CiAgICAgICAgdHJlZVtpXT0xOwogICAgfQogICAgZm9yKGludCBpPW4tMTsgaTsgLS1pKXsKICAgICAgICBpbnQgaj1pPDwxOwogICAgICAgIHRyZWVbaV09dHJlZVtqXSt0cmVlW2p8MV07CiAgICB9CiAgICByZXR1cm47Cn0KCmludCBmaW5kX2t0aChpbnQgaywgaW50IHY9MSl7CiAgIGlmKHY+PW4pewogICAgICAgcmV0dXJuIHYtbisxOwogICB9CiAgIGludCBsZWZ0PXY8PDEsIGxlZnRfdmFsdWU9dHJlZVtsZWZ0XTsKICAgaWYobGVmdF92YWx1ZT49ayl7CiAgICAgICByZXR1cm4gZmluZF9rdGgoaywgbGVmdCk7CiAgIH0KICAgcmV0dXJuIGZpbmRfa3RoKGstbGVmdF92YWx1ZSwgbGVmdHwxKTsKfQoKdm9pZCBkZWNyZW1lbnQoaW50IHBvcyl7CiAgICAgcG9zKz1uLTE7CiAgICAgd2hpbGUocG9zKXsKICAgICAgICAtLXRyZWVbcG9zXTsKICAgICAgICBwb3M+Pj0xOwogICAgIH0KfQoKaW50IG1haW4oKXsKICAgIHNjYW5mKCIlZCVkIiwmbiwmayk7CiAgICBpbml0X3RyZWUoKTsKICAgIGludCBrMj1rLTI7CiAgICBpbnQgY3VyPTE7CiAgICBpbnQgc2hpZnQ9ZmluZF9rdGgoMSk7CiAgICBmb3IoaW50IGk9MTsgaTw9bjsgKytpKXsKICAgICAgICBjdXI9MSsoY3VyK2syKSUobi1pKzEpOwogICAgICAgIGludCB4PWZpbmRfa3RoKGN1cik7CiAgICAgICAgaW50IHJlYWxfeD0oeC1zaGlmdCtuKSVuKzE7CiAgICAgICAgZGVjcmVtZW50KHgpOwogICAgICAgIGludCB5PXJlYWxfeC1pOwogICAgICAgIGludCBtYXNrPXk+PjMxOwogICAgICAgIGFuc149KHkrbWFzaylebWFzazsKICAgIH0KICAgIHByaW50ZigiJWQiLGFucyk7CiAgICByZXR1cm4gMDsKfQo=