#include<iostream>
#include<queue>
using namespace std;
int n,k;
queue<int>q;
int d[100005];
void bfs(int n,int k){
~~ while(q.size()){~~
~~ int f=q.front();~~
q.pop();
if(fk){
cout<<d[f];
break;
}
if(f-1>=0&&d[f-1]-1){
q.push(f-1);
d[f-1]=d[f]+1;
}
if(f+1<=100000&&d[f+1]-1){
q.push(f+1);
d[f+1]=d[f]+1;
}
if(f2<=100000&&d[f2]-1){
q.push(f2);
d[f2]=d[f]+1;
}
}
}
int main(){
cin>>n>>k;
for(int i=1;i<=100000;i++){
d[i]=-1;
}
q.push(n);
d[n]=0;
bfs(n,k);
return 0;
}