a,b=gets.split.map &:to_i
d=a.gcd b
x=[a/d,b/d].sort
y=[1,2,3]-x
c=d*y[0]
p y.size>1 ? -1 : c