1 #include<iostream>
2 using namespace std;
3 #include<queue>
4 struct node{
5 int x,step;
6 }cur,net;
7 queue<node>s;
8 bool num[100000];
9 int n,m;
10 void bfs()
11 {
12 cur.x=n;
13 cur.step=0;
14 s.push(cur);
15 num[n]=1;
16 while(!s.empty() )
17 {
18 cur=s.front() ;
19 s.pop() ;
20 int a=cur.x;
21 if(a*2>0&&a*2<=100000&&!num[a*2]&&a<=m)
22 {
23 if(a*2==m)
24 {
25 cout<<cur.step+1;
26 return ;
27 }
28 net.x =a*2;
29 net.step=cur.step +1;
30 s.push(net);;
31 num[a*2]=1;
32 }
33 if(a+1>0&&a+1<=100000&&!num[a+1])
34 {
35 if(a+1==m)
36 {
37 cout<<cur.step +1;
38 return ;
39 }
40 net.x =a+2;
41 net.step=cur.step +1;
42 s.push(net);
43 num[a+2]=1;
44 }
45 if(a-1>0&&a-1<=100000&&!num[a-1])
46 {
47 if(a-1==m)
48 {
49 cout<<cur.step +1;
50 return ;
51 }
52 net.x =a-2;
53 net.step=cur.step +1;
54 s.push(net);;
55 num[a-2]=1;
56 }
57 }
58 }
59 int main()
60 {
61 cin>>n>>m;
62 if(n>=m)
63 {
64 cout<<n-m;
65 return 0;
66 }
67 bfs();
68 return 0;
69 }