# include using namespace std; typedef long long ll; ll a, b; int main() { scanf("%lld%lld", &a, &b); if (a < b) { printf("%lld\n", b - 2); } else if (a > b) { printf("%lld\n", 2000000000 - b - 1); } else puts("0"); return 0; }