program zht;
var
a,b,ans:longint;
begin
assign(input,'cf520B.in');
assign(output,'cf520B.out');
reset(input);
rewrite(output);
readln(a,b);
if a>b then begin writeln(a-b);exit;end;
while b<>1 do
begin
if b mod 2=0 then begin b:=b div 2;ans:=ans+1;end else begin b:=(b+1) div 2;ans:=ans+2;end;
if a>=b then begin writeln(ans+a-b);exit;end;
end;
close(input);
close(output);
end.