import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.LinkedList;
import java.util.Queue;
import java.util.StringTokenizer;

public class Main {
    static long A;
    static long B;
    public static void main(String[] args) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        StringTokenizer st = new StringTokenizer(br.readLine());
        A = Long.parseLong(st.nextToken());
        B = Long.parseLong(st.nextToken());
        System.out.println(bfs(A, B));
    }

    static int bfs(Long A, Long B) {
        if (A == B) { // 두 수가 같으면 1반환
            return 1;
        }
        Queue<Long> queue = new LinkedList<>();
        queue.offer(A);
        int count = 1;
        while (!queue.isEmpty()) {
            int size = queue.size();
            for (int i = 0; i < size; i++) {
                long num = queue.poll();
                long newA1 = num * 2;
                long newA2 = Long.parseLong(Long.toString(num) + "1");

                if (newA1 == B || newA2 == B) { //정답 반환
                    count++;
                    return count;
                }

                queue.offer(newA1);
                queue.offer(newA2);
            }

            //queue안의 숫자들이 모두 B보다 크다면 -1 반환
            for (Long j : queue) {
                boolean check = false;
                if (j < B) {
                    check = true;
                    break;
                }
                if (!check) {
                    return -1;
                }
            }
            count++;
        }
        return count;
    }
}
