def getlist(): return list(map(int, input().split())) A, B = getlist() A, B = sorted([A, B]) if B % A != 0: print(-1) else: if int(B // A) == 2: print(A * 3) elif int(B // A) == 3: print(A * 2) else: print(-1)