#include using namespace std; typedef long long ll; #define in(T,V) T V;cin>>V; int main(){ in(ll,A); in(ll,B); ll res = 0; if(A < B){ res = B-2; } else { res = 2000000000-B-1; } cout << res << endl; }