#include <iostream>
#include <cmath>
using namespace std;
int main(){
long long a, answer=0;
int n, bits[64]={0}, i=0;
cin>>a>>n;
while(a!=0){
if(a%2==0)
a/=2;
else {
bits[i]=1;
a=(a-1)/2;
}
i++;
bits[n-1]=1-bits[n-1];
for(int j=0; j<i; j++)
answer+=bits[j]*pow(2,j);
cout<<answer;
#include <iostream>
#include <cmath>
using namespace std;
int main(){
long long a, answer=0;
int n, bits[64]={0}, i=0;
cin>>a>>n;
while(a!=0){
if(a%2==0)
a/=2;
else {
bits[i]=1;
a=(a-1)/2;
}
i++;
}
bits[n-1]=1-bits[n-1];
for(int j=0; j<i; j++)
answer+=bits[j]*pow(2,j);
cout<<answer;
}