#include <cstdio>
#include <map>

typedef long long LL;

LL x, y;

std::map<LL, LL> mp;

inline LL abs_(LL x) { return x < 0 ? -x : x; }
inline LL min_(LL a, LL b, LL c) { return a > b ? (b > c ? c : b) : (a > c ? c : a); }
inline LL min_(LL a, LL b) { return a > b ? b : a; }

LL solve(LL t) {
	if(mp[t]) return mp[t];
	else if(t == 1) return mp[t] = abs_(x - t);
	else if(t & 1) return mp[t] = min_(abs_(x - t), solve((t + 1) / 2) + 2, solve((t - 1) / 2) + 2);
	else return mp[t] = min_(abs_(x - t), solve(t / 2) + 1);
}

int main() {
	std::scanf("%lld%lld", &x, &y);
	std::printf("%lld\n", solve(y));
	return 0;
}
#include<bits/stdc++.h>
using namespace std;

int main(){
    int x,y;
    cin >> x >> y;
    int ans=0;
    if(x==y){
        ans=x;
    }else{
        ans=3-x-y;
    }
    cout << ans <<endl;
}