#include int main(void){ int A, B; scanf ("%d%d", &A, &B); 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; }