import math def my_lcm(x, y): return (x * y) // math.gcd(x, y) A,B = map(int,input().split()) if math.gcd(A,B)>1: print(-1) exit() ans = 0 lcm = my_lcm(A,B) L=[0]*(lcm+1) for j in range(101): for k in range(101): if A*j+B*k<=lcm: L[A*j+B*k]=1 print(len(L)-sum(L))