#include using namespace std; int main() { ios::sync_with_stdio(false); cin.tie(0); long long a, b; cin >> a >> b; if(a > b) { cout << a - b + 2000000000 - a - 1 << endl; return 0; } else { cout << b - 2 << endl; } return 0; }