#include int main(){ int a,b,result; scanf("%d %d",&a,&b); (b>a)?(result=(b-a-1)+(a-1)):(result=(a-b-1)+(2000000000-a)); printf("%d\n",result); return 0; }