program COLLATZ710(input, output);
(*uses crt;*)
const   PATH_LENGTH = 238;
type    massiv = array [1..PATH_LENGTH] of cardinal;
        path = record length : 0..PATH_LENGTH; numbers : massiv end;
function F(X : cardinal) : cardinal;
begin
      if (X mod 2) = 0 then F := X div 2 else F := 3 * X + 1
end;
procedure APPEND (V : cardinal; var P : PATH);
begin with P do begin
        length := length + 1;
        numbers[length] := V
      end
end;
procedure PATHTO1 (N : cardinal; var P : path);
begin
      P.length := 0;
      while N > 1 do begin
          APPEND(N, P);
          N := F(N);
      end;
        APPEND(1, P)
end;

var  N1, N2 : cardinal;
     I, J, RESULT : cardinal;
     P1, P2 : path;
begin
    readln(N1);
    read(N2);
    if N1=N2 then write(0) else begin
      if N1 > 1 then I := F(N1) else I := N1;
      if N2 > 1 then J := F(N2) else J := N2;
      if (I = N2) or (J = N1) then write(1) else begin
        PATHTO1(N1, P1);
        PATHTO1(N2, P2);
        I := P1.length;
        J := P2.length;
        while (I > 0) and (J > 0) and (P1.numbers[I] = P2.numbers[J]) do begin
          I := I - 1;
          J := J - 1;
        end;
        RESULT := I+J;
        if ((N2 = 1) and (N1 > 2)) or ((N1 = 1) and (N2 > 2)) then RESULT := RESULT - 1; 
        write(RESULT);
      end
    end
end.
