#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";
    }
}
