def main(): a,b = map(int,input().split()) for c in range(10**9): if (a+b)%c == 0 and (a+c)%b == 0 and (c+b)%a==0: print(c) return print(-1) main()