from math import gcd a,b=map(int,input().split()) g=gcd(a,b) if g!=1: print(-1) else: S=set() for i in range(b+1): for j in range(a+1): if a*i+b*j