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