import java.util.*;
class Main {
static int[] check = new int[100001];
static int n, k;
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
n = in.nextInt();
k = in.nextInt();
if (n == k) {
System.out.println(0);
}
else {
System.out.println(bfs(n));
}
}
private static int bfs(int f){
Queue<Integer> queue = new LinkedList<>();
queue.add(f);
int idx = f;
int a = 0;
check[idx] = 1;
while(queue.isEmpty() == false){
a = queue.remove();
if(a == k){
return check[a] - 1; // 1부터 시작했음: 0으로 방문여부 판단하기 위해
}
if(a-1>=0 && check[a-1] == 0){
check[a - 1] = check[a] + 1;
queue.add(a - 1);
}
if(a+1<=100000 && check[a+1] == 0){
check[a + 1] = check[a] + 1;
queue.add(a + 1);
}
if(a*2<=100000 && check[a*2] == 0){
check[a * 2] = check[a] + 1;
queue.add(a * 2);
}
}
return -1;
}
}