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