#include<bits/stdc++.h>
using namespace std;
template<typename T>inline T read(){
	T f=0,x=0;char c=getchar();
	while(!isdigit(c)) f=c=='-',c=getchar();
	while(isdigit(c)) x=x*10+c-48,c=getchar();
	return f?-x:x;
}
#define int long long
namespace run{
	const int MAX=1LL<<62;
	int X,Y,ans,num[109+9];
	int main(){
		X=read<int>(),Y=read<int>(),ans=max(X,Y);
		for(int i=0;i<=64;i++){
			int tmp=X,peg=1;
			for(int j=0;j<i;j++){
				tmp<<=1;
				if(tmp>MAX){peg=0;break;}
			}
			if(!peg) break;
			int del=abs(Y-tmp);
			for(int j=0;j<64;j++) num[j]=(del>>j&1);
			
			int g=i;
			for(int j=0;j<i;j++)
				if(num[j]==1){
					int k=j;
					while(k+1<i && num[k+1]) k++;
					g++;
					if(j^k){
						if(k+1<i) num[k+1]=1;
						else g++;
					}
					j=k;
				}
			g+=(del>>i),ans=min(ans,g);
		}
		cout<<ans<<endl;
		return 0;
	}
}
#undef int
int main(){
#ifdef my
	freopen(".in","r",stdin);
	freopen(".out","w",stdout);
#endif
	return run::main();
}
#include "bits/stdc++.h"
using namespace std;
#define int long long

int x, y;
map<int, int> dp;

int recurse(int n) {
	if (n <= x) {
		return abs(x - n);
	}
	if (n % 2 == 0) {
		if (dp[n / 2] == 0)
			dp[n] = recurse(n / 2) + 1;
		else
			dp[n] = dp[n / 2] + 1;
		dp[n] = min(dp[n], abs(x - n));
		return dp[n];
	}
	else {
		if (dp[n + 1] == 0)
			dp[n] = recurse(n + 1) + 1;
		else
			dp[n] = dp[n + 1] + 1;
		if (dp[n - 1] == 0)
			dp[n] = min(dp[n], recurse(n - 1) + 1);
		else
			dp[n] = min(dp[n], dp[n - 1] + 1);
		dp[n] = min(dp[n], abs(x - n));
		return dp[n];
	}
}

int32_t main() {
	ios::sync_with_stdio(false);
	cin.tie(nullptr);

	cin >> x >> y;
	cout << recurse(y) << "\n";
	/*for (auto i : dp) {
		cout << i.first << " " << i.second << "\n";
	}*/
	return 0;
}
