#include using namespace std; using ll = long long; int main() { int a, b; cin >> a >> b; if(a < b) { cout << a-1 << endl; } else { cout << (int)1e9 * 2 - a << endl; } }