#include using namespace std; int main() { int A, B; cin >> A >> B; cout << ((A < B) ? B - 2 : 2000000000 - B - 1) << "\n"; }