#include<iostream>
#include<algorithm>
#include<cstring>
#include<queue>
using namespace std ;
const int N = 1e5 +10 ;
queue<int> q ;
int n , m ;
int a[N*2] ;
void bfs(){
while(!q.empty()){
int now = q.front();
q.pop() ;
if(now == m) return ;
for(int i = 0 ; i < 3 ; i++){
if(i == 0){
int u = now - 1 ;
if(u<0||u>2 *N||a[u]!=-1) continue ;
q.push(u) ;
a[u] = a[now] + 1 ;
}
if(i == 1){
int u = now + 1 ;
if(u<0||u>2 *N||a[u]!=-1) continue ;
q.push(u) ;
a[u] = a[now] + 1 ;
}
if(i == 2){
int u = now * 2 ;
if(u<0||u>2 *N||a[u]!=-1) continue ;
q.push(u) ;
a[u] = a[now] + 1 ;
}
}
}
}
int main(){
cin >> n >> m ;
memset(a,-1,sizeof(a)) ;
a[n] = 0 ;
q.push(n) ;
bfs() ;
cout << a[m] << endl ;
}
10-20
365
07-09
148
07-23