#include using namespace std; int main() { unsigned int a,b,ans = 0; cin >> a >> b; cout << (a < b ? a - 1 : 2000000000 - a) << endl; return 0; }