def main(): N, M = map(int, input().split()) if N == 2 or N <= M: ans = 1 elif not N & 1 and N // 2 < M: ans = N // 2 else: ans = -1 print(ans) main()