#include using ll = long long int; using namespace std; ll mod=1e9+7; int main(){ int n,k; cin >> n >> k; if(k>=n+1){cout << -1 << endl; return 0;} cout << k-1 << endl; }