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