#include <bits/stdc++.h>
using namespace std;

#define rep(i, a) for(int i=0;i<a;i++)
#define l list
#define v vector
#define u_p unordered_map
typedef long long ll;
const int mxN=1000;
int s[4];
void solve(){
	rep(i,4)cin>>s[i];
	cout<<s[1]-s[2];
}	

int main(){
	ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
	int t=1;
	while(t--)solve();
}

#include<bits/stdc++.h>
#define int long long
using namespace std;
inline int read(){
	int res=0;
	bool zf=0;
	char c;
	while(((c=getchar())<'0'||c>'9')&&c!='-');
	if(c=='-')zf=1;
	else res=c-'0';
	while((c=getchar())>='0'&&c<='9')res=(res<<3)+(res<<1)+c-'0';
	if(zf)return -res;
	return res;
}
unordered_map<int,int>M;
int a;
int solve(int x){
	if(x==a){
		return 0;
	}
	if(x==1){
		return abs(x-a);
	}
	if(M[x]){
		return M[x];
	}
	if(x&1){
		return M[x]=min(min(abs(x-a),solve((x-1)/2)+2),solve((x+1)/2)+2);
	}
	return M[x]=min(abs(x-a),solve(x/2)+1);
}
signed main(){
	a=read();int y=read();
	printf("%lld\n",solve(y));
	return 0;
}