#include<cstdio>
#include<cstring>
#include<cstdlib>
#include <iostream>
#include <algorithm>
#include <queue>
#define m 100005
using namespace std;
queue<int> q;//用队列做广搜
bool vis[m];//用于标记路是否走过
int step[m];//记录时间
int bfs( int n, int k)
{
int head, next;// 头和下一个情况
q.push(n);
vis[n] = true;
step[n] = 0;
while (!q.empty())
{
head = q.front();
q.pop();
for (int i = 0; i < 3; i++)
{
if (i == 0)
next = head - 1;
else if (i == 1)
next = head + 1;
else
next = head * 2;
if (next < 0 || next > m||vis[next])
continue;
if (!vis[next])
{
q.push(next);
step[next] = step[head] + 1;
vis[next] = true;
}
//printf("%d %d\n",next,step[next]);
if (next == k) return step[next];
}
}
}
int main()
{
int n, k;
cin>>n>>k;
if (n>=k)
{
cout<<n-k<<endl;
}
else
{
cout<<bfs(n,k)<<endl;
}
return 0;
}
#include<cstring>
#include<cstdlib>
#include <iostream>
#include <algorithm>
#include <queue>
#define m 100005
using namespace std;
queue<int> q;//用队列做广搜
bool vis[m];//用于标记路是否走过
int step[m];//记录时间
int bfs( int n, int k)
{
int head, next;// 头和下一个情况
q.push(n);
vis[n] = true;
step[n] = 0;
while (!q.empty())
{
head = q.front();
q.pop();
for (int i = 0; i < 3; i++)
{
if (i == 0)
next = head - 1;
else if (i == 1)
next = head + 1;
else
next = head * 2;
if (next < 0 || next > m||vis[next])
continue;
if (!vis[next])
{
q.push(next);
step[next] = step[head] + 1;
vis[next] = true;
}
//printf("%d %d\n",next,step[next]);
if (next == k) return step[next];
}
}
}
int main()
{
int n, k;
cin>>n>>k;
if (n>=k)
{
cout<<n-k<<endl;
}
else
{
cout<<bfs(n,k)<<endl;
}
return 0;
}