from math import gcd a,b = map(int,input().split()) if gcd(a,b) > 1: print(-1) else: count = [1]*(10**6) for i in range(500): for j in range(500): count[i*a+b*j] = 0 print(sum(count[:a*b//gcd(a,b)]))