n, k = map(int, input().split()) if n < k: print(-1) exit() else: print(k - 1) #a = [[int(i) for i in input().split()] for _ in range(n)]