import math a,b=map(int,input().split()) c=math.gcd(a,b) d=c i=1 while c<=a+b: if (a+b)%c==0 and (a+c)%b==0 and (b+c)%a==0 and a!=b and b!=c and c!=a: print(c) break else: i+=1 c=d*i else: print(-1)