#include <stdio.h>
#include <iostream>
#include <queue>
#include <string.h>
using namespace std;
struct item_t{
int u, w;
item_t(){}
item_t(int uu, int ww){
u = uu, w = ww;
}
bool operator< (const item_t& b) const{
return w > b.w;
}
};
int cost[2000000];
int disj(int src, int dest)
{
priority_queue<item_t> que;
que.push(item_t(src, 0));
while(!que.empty()){
int u = que.top().u;
int w = que.top().w;
que.pop();
if(0 <= u && u <= 100000 && u == dest) return w;
if(0 <= u && u <= 100000 && (cost[u] == -1 || w < cost[u])){
cost[u] = w;
que.push(item_t(u - 1, w + 1));
que.push(item_t(u + 1, w + 1));
que.push(item_t(u * 2, w + 1));
}
}
return -1; // WA if I exclude this
}
int main()
{
for(; ;){
memset(cost, -1, sizeof(cost));
int n, k;
if(!(cin >> n >> k)) break;
cout << disj(n, k) << "\n";
}
}
I2luY2x1ZGUgPHN0ZGlvLmg+CiNpbmNsdWRlIDxpb3N0cmVhbT4KI2luY2x1ZGUgPHF1ZXVlPgojaW5jbHVkZSA8c3RyaW5nLmg+Cgp1c2luZyBuYW1lc3BhY2Ugc3RkOwoKc3RydWN0IGl0ZW1fdHsKICAgIGludCB1LCB3OwoKICAgIGl0ZW1fdCgpe30KICAgIGl0ZW1fdChpbnQgdXUsIGludCB3dyl7CiAgICAgICAgdSA9IHV1LCB3ID0gd3c7CiAgICB9CgogICAgYm9vbCBvcGVyYXRvcjwgKGNvbnN0IGl0ZW1fdCYgYikgY29uc3R7CiAgICAgICAgcmV0dXJuIHcgPiBiLnc7CiAgICB9Cn07CgppbnQgY29zdFsyMDAwMDAwXTsKaW50IGRpc2ooaW50IHNyYywgaW50IGRlc3QpCnsKICAgIHByaW9yaXR5X3F1ZXVlPGl0ZW1fdD4gcXVlOwogICAgcXVlLnB1c2goaXRlbV90KHNyYywgMCkpOwogICAgd2hpbGUoIXF1ZS5lbXB0eSgpKXsKICAgICAgICBpbnQgdSA9IHF1ZS50b3AoKS51OwogICAgICAgIGludCB3ID0gcXVlLnRvcCgpLnc7CiAgICAgICAgcXVlLnBvcCgpOwogICAgICAgIGlmKDAgPD0gdSAmJiB1IDw9IDEwMDAwMCAmJiB1ID09IGRlc3QpIHJldHVybiB3OwogICAgICAgIGlmKDAgPD0gdSAmJiB1IDw9IDEwMDAwMCAmJiAoY29zdFt1XSA9PSAtMSB8fCB3IDwgY29zdFt1XSkpewogICAgICAgICAgICBjb3N0W3VdID0gdzsKICAgICAgICAgICAgcXVlLnB1c2goaXRlbV90KHUgLSAxLCB3ICsgMSkpOwogICAgICAgICAgICBxdWUucHVzaChpdGVtX3QodSArIDEsIHcgKyAxKSk7CiAgICAgICAgICAgIHF1ZS5wdXNoKGl0ZW1fdCh1ICogMiwgdyArIDEpKTsKICAgICAgICB9CiAgICB9CiAgICByZXR1cm4gLTE7IC8vIFdBIGlmIEkgZXhjbHVkZSB0aGlzIAp9CgppbnQgbWFpbigpCnsKICAgIGZvcig7IDspewogICAgICAgIG1lbXNldChjb3N0LCAtMSwgc2l6ZW9mKGNvc3QpKTsKICAgICAgICBpbnQgbiwgazsKICAgICAgICBpZighKGNpbiA+PiBuID4+IGspKSBicmVhazsKICAgICAgICBjb3V0IDw8IGRpc2oobiwgaykgPDwgIlxuIjsKICAgIH0KfQo=