a,b=gets.split.map(&:to_i).sort g=a.gcd b a/=g b/=g r=case[a,b] when[1,1],[2,3];g when[1,2];3*g when[1,3];2*g else;-1 end p r>10**9?-1:r