#include<bits/stdc++.h>usingnamespace std;constint N =2e5+10;int n, k;int path[N];
queue<int> q;intop(int n,int t){if(t ==1)return n -1;if(t ==2)return n +1;if(t ==3)return n *2;}intbfs(int n,int k){memset(path,0,sizeof(path));
q.push(n);
path[n]==0;while(q.size()){auto t = q.front(); q.pop();for(int i =1; i <=3; i++){int result =op(t, i);if(result >=0&& result <= k +1&& path[result]==0){
path[result]= path[t]+1;if(result == k)return path[result];
q.push(result);}}}return-1;}intmain(){
cin >> n >> k;if(n >= k){
cout << n - k;return0;}
cout <<bfs(n, k)<< endl;return0;}