X,Y = list(map(int,input().split()))

flag = -1

if X!=Y:

    for i in range(1,10**9//(X)+1):

        if i*X%Y!=0:

            flag = i*X

            break

print(flag)
X,Y = list(map(int,input().split()))

if X%Y==0:

    print((-1))

else:

    print(X)
X, Y = list(map(int, input().split()))
flag = -1
if X != Y:
    for i in range(1, 10**9 // (X) + 1):
        if i * X % Y != 0:
            flag = i * X
            break
print(flag)

X, Y = list(map(int, input().split()))
if X % Y == 0:
    print((-1))
else:
    print(X)

-flag = -1 -if X != Y: -    for i in range(1, 10**9 // (X) + 1): -        if i * X % Y != 0: -            flag = i * X -            break -print(flag) +if X % Y == 0: +    print((-1)) +else: +    print(X)