#include using namespace std; int main(){ int N, K; cin >> N >> K; if (K > N){ cout << -1 << endl; } else { cout << K - 1 << endl; } }