#include int main(void){ int A, B; scanf ("%d%d", &A, &B); if ( A + 1 == B){ printf ( "%d\n", A - 1); }else if ( A == B + 1){ printf ( "%d\n", 2000000000 - A); }else if ( A < B && A + 1 != B){ printf ( "%d\n", B - 2); }else if ( B < A && A != B + 1){ printf ( "%d\n", 1999999999 - B); } return 0; }