#include #include #include #include #include #include #include #include #include #include #include #include using namespace std; #define INF (1 << 30) #define INFLL (1LL << 60) int main() { long long a,b,c; cin >> a >> b; if(a < b) cout << a - 1 << endl; else cout << 2000000000 - a + (a-b-1)<< endl; return 0; }