import java.util.Scanner;
class Data{
public int posi;
public int step;
public Data(int posi, int step) {
this.posi = posi;
this.step = step;
}
public int getPosi() {
return posi;
}
public int getStep() {
return step;
}
}
class Queue{
public Data[] myData=new Data[10000000];
public int front=0;
public int rear=0;
public void push(Data mydata){
myData[rear++]=mydata;
}
public Data pop( ){
return myData[front++];
}
public boolean isEmpty( ){
return front==rear;
}
}
public class Main {
public static int[] visit;
public static void bFS(int x1,int x2){
Data oriData=new Data(x1,0);
Queue myQueue=new Queue();
myQueue.push(oriData);
while(!myQueue.isEmpty()){
Data curData=myQueue.pop();
int curposi=curData.posi;
int curstep=curData.step;
if(curposi==x2){
System.out.println(curstep);
break;
}
Data nextData;
int nextposi=curposi-1;
if(nextposi>=0&&nextposi<=100000&&visit[nextposi]==0){
visit[nextposi]=1;
nextData=new Data(nextposi,curstep+1);
myQueue.push(nextData);
}
nextposi=curposi+1;
if(nextposi>=0&&nextposi<=100000&&visit[nextposi]==0){
visit[nextposi]=1;
nextData=new Data(nextposi,curstep+1);
myQueue.push(nextData);
}
nextposi=curposi*2;
if(nextposi>=0&&nextposi<=100000&&visit[nextposi]==0){
visit[nextposi]=1;
nextData=new Data(nextposi,curstep+1);
myQueue.push(nextData);
}
}
}
public static void main(String[] args){
Scanner sc=new Scanner(System.in);
int N=sc.nextInt();
int K=sc.nextInt();
visit=new int[100001];
bFS(N,K);
}
}
class Data{
public int posi;
public int step;
public Data(int posi, int step) {
this.posi = posi;
this.step = step;
}
public int getPosi() {
return posi;
}
public int getStep() {
return step;
}
}
class Queue{
public Data[] myData=new Data[10000000];
public int front=0;
public int rear=0;
public void push(Data mydata){
myData[rear++]=mydata;
}
public Data pop( ){
return myData[front++];
}
public boolean isEmpty( ){
return front==rear;
}
}
public class Main {
public static int[] visit;
public static void bFS(int x1,int x2){
Data oriData=new Data(x1,0);
Queue myQueue=new Queue();
myQueue.push(oriData);
while(!myQueue.isEmpty()){
Data curData=myQueue.pop();
int curposi=curData.posi;
int curstep=curData.step;
if(curposi==x2){
System.out.println(curstep);
break;
}
Data nextData;
int nextposi=curposi-1;
if(nextposi>=0&&nextposi<=100000&&visit[nextposi]==0){
visit[nextposi]=1;
nextData=new Data(nextposi,curstep+1);
myQueue.push(nextData);
}
nextposi=curposi+1;
if(nextposi>=0&&nextposi<=100000&&visit[nextposi]==0){
visit[nextposi]=1;
nextData=new Data(nextposi,curstep+1);
myQueue.push(nextData);
}
nextposi=curposi*2;
if(nextposi>=0&&nextposi<=100000&&visit[nextposi]==0){
visit[nextposi]=1;
nextData=new Data(nextposi,curstep+1);
myQueue.push(nextData);
}
}
}
public static void main(String[] args){
Scanner sc=new Scanner(System.in);
int N=sc.nextInt();
int K=sc.nextInt();
visit=new int[100001];
bFS(N,K);
}
}