#include <bits/stdc++.h> using namespace std; int main(){ int a,b; cin>>a>>b; if(a<b)cout<<a-1+b-a-1; else cout<<(int)2e9-a+a-b-1; cout<<"\n"s; }