#include<bits/stdc++.h>
#define ll long long
#define ld long double
#define fi first
#define se second
#define pb push_back
#define pp pop
#define p push
using namespace std;
const int N = 2e5 + 9;
int n,m,cnt_trace[N];
vector<int> a[N];
bool visited[N];
void bfs(int x)
{
queue<int> q;
q.p(x);
visited[x] = true;
while (q.size()!=0)
{
int y = q.front();
q.pp();
for(auto z:a[y])
if(!visited[z])
{
q.p(z);
visited[z] = true;
cnt_trace[z] = cnt_trace[y]+1;
}
}
}
int main()
{
//freopen("thaotacvoiso.inp","r",stdin);
//freopen("thaotacvoiso.out","w",stdout);
ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
cin>>n>>m;
if(n>=m)
cout<<n-m;
else
{
for(int i=1;i<=m+1;++i)
{
a[i].pb(i-1);
a[i].pb(i*2);
}
memset(visited,false,N);
cnt_trace[n] = 0;
bfs(n);
cout<<cnt_trace[m];
}
return 0;
}
I2luY2x1ZGU8Yml0cy9zdGRjKysuaD4KI2RlZmluZSBsbCBsb25nIGxvbmcKI2RlZmluZSBsZCBsb25nIGRvdWJsZQojZGVmaW5lIGZpIGZpcnN0CiNkZWZpbmUgc2Ugc2Vjb25kCiNkZWZpbmUgcGIgcHVzaF9iYWNrCiNkZWZpbmUgcHAgcG9wCiNkZWZpbmUgcCBwdXNoCnVzaW5nIG5hbWVzcGFjZSBzdGQ7CmNvbnN0IGludCBOID0gMmU1ICsgOTsKaW50IG4sbSxjbnRfdHJhY2VbTl07CnZlY3RvcjxpbnQ+IGFbTl07CmJvb2wgdmlzaXRlZFtOXTsKdm9pZCBiZnMoaW50IHgpCnsKICAgIHF1ZXVlPGludD4gcTsKICAgIHEucCh4KTsKICAgIHZpc2l0ZWRbeF0gPSB0cnVlOwogICAgd2hpbGUgKHEuc2l6ZSgpIT0wKQogICAgewogICAgICAgIGludCB5ID0gcS5mcm9udCgpOwogICAgICAgIHEucHAoKTsKICAgICAgICBmb3IoYXV0byB6OmFbeV0pCiAgICAgICAgICAgIGlmKCF2aXNpdGVkW3pdKQogICAgICAgIHsKICAgICAgICAgICAgcS5wKHopOwogICAgICAgICAgICB2aXNpdGVkW3pdID0gdHJ1ZTsKICAgICAgICAgICAgY250X3RyYWNlW3pdID0gY250X3RyYWNlW3ldKzE7CiAgICAgICAgfQogICAgfQp9CmludCBtYWluKCkKewogICAgLy9mcmVvcGVuKCJ0aGFvdGFjdm9pc28uaW5wIiwiciIsc3RkaW4pOwogICAgLy9mcmVvcGVuKCJ0aGFvdGFjdm9pc28ub3V0IiwidyIsc3Rkb3V0KTsKICAgIGlvczo6c3luY193aXRoX3N0ZGlvKDApO2Npbi50aWUoMCk7Y291dC50aWUoMCk7CiAgICBjaW4+Pm4+Pm07CiAgICBpZihuPj1tKQogICAgICAgIGNvdXQ8PG4tbTsKICAgIGVsc2UKICAgIHsKICAgICAgICBmb3IoaW50IGk9MTtpPD1tKzE7KytpKQogICAgICAgIHsKICAgICAgICAgICAgYVtpXS5wYihpLTEpOwogICAgICAgICAgICBhW2ldLnBiKGkqMik7CiAgICAgICAgfQogICAgICAgIG1lbXNldCh2aXNpdGVkLGZhbHNlLE4pOwogICAgICAgIGNudF90cmFjZVtuXSA9IDA7CiAgICAgICAgYmZzKG4pOwogICAgICAgIGNvdXQ8PGNudF90cmFjZVttXTsKICAgIH0KICAgIHJldHVybiAwOwp9