#include<cstdio>
namespace cat{
int work(int x){
int t=0;
while( x > 0 ){
x = x - ( x & -x );
t++;
}
return t;
}
int dooaaa(){
#define doo
#ifdef doo
freopen("watera.in","r",stdin);
freopen("watera.out","w",stdout);
#endif
int n,k;scanf("%d%d",&n,&k);
int ans = 0;
while( work(n) > k ){
ans += (n & -n);
n = n + (n & -n) ;
}
printf("%d",ans);
#ifdef doo
fclose(stdin);fclose(stdout);
#endif
return 0;
}
}
int ttt = cat::dooaaa() ;
int main(){;}