from math import gcd A, B = map(int, input().split()) if gcd(A, B) > 1: print(-1) exit() X = set() for i in range(2 * B + 1): for j in range(2 * A + 1): c = i * A + j * B if c <= A * B: X.add(c) print(A * B - len(X) + 1)