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