#include #define PI 3.14159265359 using namespace std; const int64_t MOD = 1e9 + 7; int main() { int64_t A, B; cin >> A >> B; if (A < B) { cout << A - 1 + B - A - 1 << endl; } else { cout << 2000000000 - A + A - B - 1 << endl; } }