#yuki816 import sys a,b=map(int,raw_input().split()) if 2*a==b: c=3*a elif 3*a==b: c=2*a elif 2*b==a: c=3*b elif 3*b==a: c=2*b elif 3*a==2*b: c=a/2 elif 3*b==2*a: c=b/2 else: print -1 sys.exit() print c