#include <iostream>
#include <set>
#include <cmath>
#include <queue>
#include <stack>
#include <vector>
#include <string>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <functional>
#include <map>
using namespace std;
int ans = 0;
int vis[1000005];
int k,n;
typedef pair <int ,int > P;
int bfs()
{
queue<P> que;
memset(vis,0,sizeof(vis));
que.push(P(n,0));
vis[n] = 1;
while(que.size())
{
P p = que.front();
que.pop();
if(p.first == k)
break;
for(int i = 0; i < 3;i++)
{
int dx;
if(i == 0)
{
dx = p.first + 1;
}
if(i == 1)
{
dx = p.first - 1;
}
if(i == 2)
{
dx = p.first * 2;
}
p.second++;
if (p.first == k)
{
return p.second;
}
if (dx >= 0 && dx <= 200000 && vis[dx] == 0)
{
vis[dx] = 1;
que.push(P(dx,p.second));
}
}
}
}
int main()
{
cin >> n >> k;
cout << bfs() << endl;
}
#include <set>
#include <cmath>
#include <queue>
#include <stack>
#include <vector>
#include <string>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <functional>
#include <map>
using namespace std;
int ans = 0;
int vis[1000005];
int k,n;
typedef pair <int ,int > P;
int bfs()
{
queue<P> que;
memset(vis,0,sizeof(vis));
que.push(P(n,0));
vis[n] = 1;
while(que.size())
{
P p = que.front();
que.pop();
if(p.first == k)
break;
for(int i = 0; i < 3;i++)
{
int dx;
if(i == 0)
{
dx = p.first + 1;
}
if(i == 1)
{
dx = p.first - 1;
}
if(i == 2)
{
dx = p.first * 2;
}
p.second++;
if (p.first == k)
{
return p.second;
}
if (dx >= 0 && dx <= 200000 && vis[dx] == 0)
{
vis[dx] = 1;
que.push(P(dx,p.second));
}
}
}
}
int main()
{
cin >> n >> k;
cout << bfs() << endl;
}