program zzn;
var
i,j,k,n,s,n2,ans,s2:longint;
procedure init;
begin
assign(input,'watera.in');
reset(input);
assign(output,'watera.out');
rewrite(output);
readln(n,k);
end;
procedure closef;
begin
close(input);
close(output);
end;
{procedure main;
begin
n2:=n;
s:=0;
ans:=0;
while true do
begin
while n2 mod 2 =0 do
begin
inc(s);
n2:=n2 div 2;
if n2<=k then
begin
writeln(ans);
exit;
end;
end;
s2:=trunc(exp(s*ln(2)));
inc(ans,s2);
inc(n2);
end;
writeln(ans);
end; }
procedure main;
begin
for i:=0 to 100000000 do
begin
n2:=n+i;
while n2 mod 2=0 do
begin
n2:=n2 div 2;
end;
if n2<=k then
begin
writeln(i);
exit;
end;
end;
end;
begin
init;
main;
closef;
end.