from math import ceil def main(): n, m = map(int, input().split()) if n <= m: print(1) return if m == 1: if n == 2: print(2) else: print(-1) return if n == 3: print(-1) return if n % 2 == 0: print(-1) return if ceil(n / 2) <= m: print(2) else: print(-1) if __name__ == "__main__": main()