#include using namespace std; int main(){ ios::sync_with_stdio(false); cin.tie(); int a, b; cin >> a >> b; cout << ((a>b) ? 2000000000-b-1 : b-2 ) << "\n"; return 0; }