program cojs1416;
var
n,k:longint;
ans:int64;
function count(x:longint):longint;
var
t:longint;
begin
t:=0;
while x>0 do
begin
x:=x-(x and (-x));
inc(t);
end;
exit(t);
end;
begin
assign(input,'pwater.in');reset(input);
assign(output,'pwater.out');rewrite(output);
readln(n,k);
ans:=0;
while count(n)>k do
begin
inc(ans,n and (-n));
n:=n+n and (-n);
end;
writeln(ans);
close(input);close(output);
end.