import sys A,B = map(int,input().split()) def gcd(a,b): while True: r = a % b a = b b = r if r == 0: return a d = gcd(A,B) if d != 1: print(-1) exit() dat = [1] * 20000 for x in range(20000): for y in range(20000): c = A * x + B * y if c < 20000: dat[c] = 0 print(sum(dat))