# include using namespace std; typedef long long ll; //# define int long long # define lc u << 1 # define rc u << 1 | 1 # define fi first # define se second int a, b; signed main () { // freopen ("missing.in", "r", stdin); freopen ("missing.out", "w", stdout); scanf ("%d%d", &a, &b); if (a < b) printf ("%d\n", b - 2); else if (a > b) printf ("%d\n", 2000000000 - b - 1); else printf ("0\n"); return 0; }