program watera;
var
a:array[1..31]of longint;
i,j,l:longint;
n,k:longint;
min:longint;
max:longint;
procedure sou(const x,y:longint);
var
i,j:longint;
begin
if k<=0 then begin min:=a[y]-x; exit; end
else
begin
for i:=1 to 30 do
if x<a[i] then
begin
j:=i-1;
dec(k);
sou(x-a[j],j);
break;
end;
end;
end;
begin
assign(input,'watera.in');
reset(input);
assign(output,'watera.out');
rewrite(output);
readln(n,k);
a[1]:=2;
for i:=2 to 30 do
a[i]:=a[i-1]*2;
min:=0;
sou(n,0);
writeln(min);
close(input);
close(output);
end.