program watera(input,output);
var
a,b:array[0..30]of longint;
i,j,k:longint;
ans,n,p:longint;
begin
assign(input,'watera.in');
reset(input);
readln(n,k);
close(input);
a[0]:=1;
for i:=1 to 30 do
a[i]:=a[i-1]*2;
i:=30;
while i>=0 do
begin
if a[i]>n then dec(i)
else
begin
inc(p);
n:=n-a[i];
b[i]:=1;
dec(i);
end;
end;
for i:=0 to 30 do
begin
if p<=k then break;
if b[i]=1 then
begin
ans:=ans+a[i];
inc(b[i+1]);
end
else
if b[i]=2 then
begin
inc(b[i+1]);
dec(p);
end;
end;
assign(output,'watera.out');
rewrite(output);
writeln(ans);
close(output);
end.