#include using namespace std; int main(){ int A, B; cin >> A >> B; if(A > B){ cout << 2000000000 - B - 1 << endl; }else{ cout << B - 2 << endl; } return 0; }