#include int main() { int a, b, c; scanf("%d %d", &a, &b); if (a < b) c = b - 2; else c = 1999999999 - b; printf("%d\n", c); return 0; }