#include <iostream>
using namespace std;
int visited[100001];
int a[100001];
int que[100001];
int move[3][2] = {{1,-1},{1,1},{2,0}};
int main()
{
int n,k;
cin>>n>>k;
int front,rear,temp;
int next;
front = 0;
rear = 1;
a[front] = n;
memset(visited,0,sizeof(visited));
memset(que,0,sizeof(que));
visited[n] = 1;
if(n>k){cout<<n-k<<endl;}
else
{
while(front<rear)
{
temp = front++;
if(a[temp]==k){cout<<que[k]<<endl;break;}
for(int i=0;i<3;i++)
{
next = a[temp]*move[i][0]+move[i][1];
if(next>=0 && next<=100000 && !visited[next])
{
visited[next] = 1;
que[next] = que[a[temp]] + 1;
a[rear++] = next;
}
}
}
}
system("pause");
}