#include using namespace std; int main() { int64_t a, b; cin >> a >> b; if (a < b) cout << b - 2 << endl; else cout << 1999999999 - b << endl; return 0; }