///POJ 3278 Catch That Cow
#include<stdio.h>
#include<string.h>
#include<iostream>
#include<queue>
using namespace std;
int step[100010];
int vis[100010];
queue <int> q;
int BFS(int n, int k)
{
int i;
int head, next;
q.push(n);
step[n]=0;
vis[n]=1;
while(!q.empty())
{
head=q.front();
q.pop();
for(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>100000) continue;
if(!vis[next])
{
q.push(next);
step[next]=step[head]+1;
vis[next]=1;
}
if(next==k) return step[next];
}
}
}
int main()
{
int n, k;
while(scanf("%d%d", &n, &k)!=EOF)
{
memset(step, 0, sizeof(step));
memset(vis, 0, sizeof(vis));
while(!q.empty()) q.pop();
if(n>=k)
printf("%d\n", n-k);
else
printf("%d\n", BFS(n, k));
}
}