#include int main() { int a,b,c; std::cin >> a >> b; (a < b) ? c = a-1 : c = 2000000000-a; std::cout << c << std::endl; }