import sys input=lambda:sys.stdin.readline().rstrip() N,K=map(int,input().split()) print(-1 if K>N else K-1)