a,b = map(int,input().split()) c = max(a,b) d = min(a,b) if c==d*2: print(d*3) elif c==d*3: print(d*2) elif c*2==d*3: print(d//2) else: print(-1)