#include using namespace std; int main() { int a, b; cin >> a >> b; int ans = a < b ? b - 2 : 2000000000 - b - 1; cout << ans << endl; return 0; }