#include using namespace std; int main() { long long a, b; cin >> a >> b; if (a == 1 || b == 2000000000){ cout << 0; }else if (a < b) { cout << a - 1; } else { cout << 2000000000 - b - 1; } }