N,K=map(int,input().split()) if K>N: print(-1) else: print(K-1)