3815 {
3816 int n;
3817 int m;
3818 cin >> n >> m;
3819 auto um = unordered_set<int>();
3820 auto que = queue<pair<int, int>>();
3821 que.push(make_pair(n, 0));
3822 um.insert(n);
3823 while(!que.empty()) {
3824 auto [current, step] = que.front();
3825 que.pop();
3826 if(current == m) {
3827 cout << step;
3828 return 0;
3829 }
3830 int k = 1;
3831 const int nexts[2] = {current - 1, current * 2};
3832 if(current < m) {
3833 k = 2;
3834 }
3835 for(int i = 0; i < k; i++) {
3836 auto next = nexts[i];
3837 if(next == m) {
3838 cout << step + 1;
3839 return 0;
3840 }
3841 if(next > 0 && !um.contains(next)) {
3842 que.push(make_pair(next, step + 1));
3843 um.insert(next);
3844 }
3845 }
3846 }
3847 return 0;
3848 }