#include int main(){ int r, m; std::cin >> r >> m; std::cout << (r < m ? m - 2 : 1999999999 - m) << "\n"; return 0; }