#include int main(){ long long r, m, ans; std::cin >> r >> m; if(r < m) ans = m - 2; else ans = 1999999999 - m; std::cout << ans << std::endl; return 0; }