import java.util.ArrayList;
import java.util.LinkedList;
import java.util.Queue;
import java.util.Scanner;
public class HideAndSeek {
static int visit[] = new int[100001];
static int first;
static int second;
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
first = sc.nextInt();
second = sc.nextInt();
bfs(first);
}
static void bfs(int node){
Queue<Integer> queue = new LinkedList<>();
queue.add(node);
int n =0;
visit[node] =1;
while(!queue.isEmpty()){
n = queue.remove();
if(n == second) {
System.out.println(visit[n]-1);
}
if(n-1>=0 && visit[n-1]==0){
visit[n-1] = visit[n]+1;
queue.add(n-1);
}
if (n+1 <= 100000 && visit[n+1]==0) {
visit[n+1]=visit[n]+1;
queue.add(n+1);
}
if(2*n <= 100000 && visit[2*n]==0){
visit[2*n] =visit[n]+1;
queue.add(2*n);
}
}
}
}