n, k = map(int,input().split()) if k > n: print(-1) elif k <= k: print(k - 1)