#include using namespace std; #define int long long signed main() { int A, B; cin >> A >> B; int ans = max(A, B) - min(A, B) + 1; if (A > B) ans += 2000000000 - A; else ans += A - 1; printf("%lld\n", ans); return 0; }