A,B=map(int,input().split()) if A==B: print(A) elif max(A,B)==min(A,B)*2: print(min(A,B)*3) elif max(A,B)==min(A,B)*3: print(min(A,B)*2) else: print(-1)