A,B = map(int,input().split()) if A > B: A,B = B,A if B//A == 2 and B%A==0: print(A*3) elif B//A ==3 and B%A==0: print(A*2) else: print(-1)