#include<bits/stdc++.h>
#define PB push_back
#define endl '\n';
using ll = long long;
using namespace std;
const int maxN = 1e6;
const int MOD = 1e9 + 7;
int dx4[4] = {-1, 0, 0, 1};
int dy4[4] = {0, -1, 1, 0};
int dx8[8] = {-1, -1, -1, 0, 0, 1, 1, 1};
int dy8[8] = {-1, 0, 1, -1, 1, -1, 0, 1};
vector<bool> visited(maxN, false);
vector<int> adj[maxN];
vector<int> parent(maxN, 0);
int n, m;
int bfs(int n, int m){
if(n >= m){
return n - m;
}
queue<pair<int, int>> q;
q.push(make_pair(n, 0));
set<int> s;
s.insert(n);
while(!q.empty()){
int x = q.front().first;
int y = q.front().second;
q.pop();
if(x == m){
return y;
}
if(s.find(x*2) == s.end()){
q.push(make_pair(x*2, y + 1));
s.insert(x*2);
}
if(x - 1 >= 0 && s.find(x - 1) == s.end()){
q.push(make_pair(x - 1, y + 1));
s.insert(x - 1);
}
}
return -1;
}
int main() {
ios_base::sync_with_stdio(0);
cin.tie(nullptr);
cout.tie(0);
cin >> n >> m;
cout << bfs(n, m);
return 0;
}
I2luY2x1ZGU8Yml0cy9zdGRjKysuaD4KI2RlZmluZSBQQiBwdXNoX2JhY2sKI2RlZmluZSBlbmRsICdcbic7CnVzaW5nIGxsID0gbG9uZyBsb25nOwp1c2luZyBuYW1lc3BhY2Ugc3RkOwpjb25zdCBpbnQgbWF4TiA9IDFlNjsKY29uc3QgaW50IE1PRCA9IDFlOSArIDc7CmludCBkeDRbNF0gPSB7LTEsIDAsIDAsIDF9OwppbnQgZHk0WzRdID0gezAsIC0xLCAxLCAwfTsKaW50IGR4OFs4XSA9IHstMSwgLTEsIC0xLCAwLCAwLCAxLCAxLCAxfTsKaW50IGR5OFs4XSA9IHstMSwgMCwgMSwgLTEsIDEsIC0xLCAwLCAxfTsKdmVjdG9yPGJvb2w+IHZpc2l0ZWQobWF4TiwgZmFsc2UpOwp2ZWN0b3I8aW50PiBhZGpbbWF4Tl07CnZlY3RvcjxpbnQ+IHBhcmVudChtY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