#include<queue>#include<iostream>#include<algorithm>
using namespace std ;constint N =100010;int stamp[N];
bool vis[N];int dir[3];
queue<int> q ;voidbfs(int n ,int k){int head ;
q.push(n);
vis[n]= true ;
stamp[n]=0;while(!q.empty()){
head = q.front();
q.pop();if(head == k){//抓住牛了,可跳出循环
cout << stamp[k]<< endl ;break;}
dir[0]= head -1;
dir[1]= head +1;
dir[2]= head *2;for(int i =0; i <3; i ++){if(dir[i]>=0&& dir[i]< N && vis[dir[i]]==false){//不能dir[i]>0否则会WA
vis[dir[i]]= true ;
stamp[dir[i]]= stamp[head]+1;
q.push(dir[i]);if(dir[i]> k)//人在牛的前面就不用再前进了(剪枝)break;}}}}intmain(){int n , k ;
cin >> n >> k ;bfs(n,k);return0;}