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