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