https://www.acmicpc.net/problem/1697
using System;
using System.Collections;
class Program
{
static int[] check;
static int n,k;
static void bfs(int a){
Queue q=new Queue();
q.Enqueue(new int[]{a,0});
check[a]=1;
while(q.Count!=0){
int[] v=(int[])q.Dequeue();
if(v[0]==k){
Console.Write(v[1]);
return;
}
if(2*v[0]<=100000 && check[2*v[0]]==0){
check[2*v[0]]=1;
q.Enqueue(new int[]{2*v[0],v[1]+1});
}
if(v[0]+1<=100000 && check[v[0]+1]==0){
check[v[0]+1]=1;
q.Enqueue(new int[]{v[0]+1,v[1]+1});
}
if(v[0]-1>=0 && check[v[0]-1]==0){
check[v[0]-1]=1;
q.Enqueue(new int[]{v[0]-1,v[1]+1});
}
}
}
static void Main() {
string[] s=Console.ReadLine().Split(' ');
n=int.Parse(s[0]);
k=int.Parse(s[1]);
check=new int[100001];
bfs(n);
}
}