n, k = list(map(int, input().split())) if n < k: print(-1) else: print(k - 1)