#include<stdio.h>
#define maxn 1100000
int fenwick[maxn+1], n;
inline void dec_after(int x){
while(1){
--fenwick[x];
x+=x&(-x);
if(x>n)
return;
}
}
inline void sum_before(int x, int &sum){
sum=0;
while(1){
sum+=fenwick[x];
if(x<=1)
return;
x-=(x)&(-x);
}
}
inline void find_kth(int k,int &res){
int up=n, low=1, cur;
while(1){
if(up==low){
res=low;
return;
}
int mid=(low+up)>>1;
sum_before(mid, cur);
if(cur+mid>=k)
up=mid;
else
low=mid+1;
}
}
int main(){
int k,cur=1,ans=0,x, i;
scanf("%d %d", &n, &k);
for(i=1; i<=n; ++i){
cur=1+(cur+k-2)%(n-i+1);
find_kth(cur, x);
dec_after(x);
ans^=(i>=x)?(i-x):(x-i) ;
}
printf("%d\n", ans);
return 0;
}
I2luY2x1ZGU8c3RkaW8uaD4KI2RlZmluZSBtYXhuIDExMDAwMDAKaW50IGZlbndpY2tbbWF4bisxXSwgbjsKaW5saW5lIHZvaWQgZGVjX2FmdGVyKGludCB4KXsKICAgIHdoaWxlKDEpewogICAgICAgIC0tZmVud2lja1t4XTsKICAgICAgICB4Kz14JigteCk7CiAgICAgICAgaWYoeD5uKQogICAgICAgICAgICByZXR1cm47CiAgICB9Cn0KaW5saW5lIHZvaWQgc3VtX2JlZm9yZShpbnQgeCwgaW50ICZzdW0pewogICAgc3VtPTA7CiAgICB3aGlsZSgxKXsKICAgICAgICBzdW0rPWZlbndpY2tbeF07CiAgICAgICAgaWYoeDw9MSkKICAgICAgICAgICAgcmV0dXJuOwogICAgICAgIHgtPSh4KSYoLXgpOwogICAgfQp9CmlubGluZSB2b2lkIGZpbmRfa3RoKGludCBrLGludCAmcmVzKXsKICAgIGludCB1cD1uLCBsb3c9MSwgY3VyOwogICAgd2hpbGUoMSl7CiAgICAgICAgaWYodXA9PWxvdyl7CiAgICAgICAgICAgIHJlcz1sb3c7CiAgICAgICAgICAgIHJldHVybjsKICAgICAgICB9CiAgICAgICAgaW50IG1pZD0obG93K3VwKT4+MTsKICAgICAgICBzdW1fYmVmb3JlKG1pZCwgY3VyKTsKICAgICAgICBpZihjdXIrbWlkPj1rKQogICAgICAgICAgICB1cD1taWQ7CiAgICAgICAgZWxzZQogICAgICAgICAgbG93PW1pZCsxOwogICAgfQp9CmludCBtYWluKCl7CiAgICBpbnQgayxjdXI9MSxhbnM9MCx4LCBpOwogICAgc2NhbmYoIiVkICVkIiwgJm4sICZrKTsKICAgIGZvcihpPTE7IGk8PW47ICsraSl7CiAgICAgICAgY3VyPTErKGN1citrLTIpJShuLWkrMSk7CiAgICAgICAgZmluZF9rdGgoY3VyLCAgeCk7CiAgICAgICAgZGVjX2FmdGVyKHgpOwogICAgICAgIGFuc149KGk+PXgpPyhpLXgpOih4LWkpIDsgCiAgICB9CiAgICBwcmludGYoIiVkXG4iLCBhbnMpOwogICAgcmV0dXJuIDA7Cn0=