#include<stdio.h>
#include<string.h>
#include<queue>
using namespace std;
#define maxn 100001
int v[maxn];//标记是否走过,防止重走
int BFS(int s, int e)
{
queue<int> Q;
Q.push(s);
v[s] = 1;
while(Q.size())
{
s = Q.front();
Q.pop();
if(s == e)
return v[s]-1;
for(int i=0; i<3; i++)
{
int q=s;
if(i == 0)
q--;
else if(i == 1)
q++;
else
q *= 2;
if(q>=0 && q <=maxn && v[q] == 0)
{
Q.push(q);
v[q] = v[s]+1;
}
}
}
return -1;
}
int main()
{
int s, e;
while(scanf("%d%d", &s, &e) != EOF)
{
memset(v, 0, sizeof(v));
int ans = BFS(s, e);
printf("%d\n", ans);
}
return 0;