def resolve():
    X, Y = [int(i) for i in input().split()]
    if X % Y == 0:
        print(-1)
    else:
        print(X)


resolve()

34c3ec6827d743e8e0c110743f91d045728b154d
<mask token>

def resolve():
    X, Y = [int(i) for i in input().split()]
    if X % Y == 0:
        print(-1)
    else:
        print(X)


<mask token>

def resolve():
    X, Y = [int(i) for i in input().split()]
    if X % Y == 0:
        print(-1)
    else:
        print(X)


resolve()
