import math a, b = map(int, input().split()) if math.gcd(a, b) != 1: print(-1) else: MAX = int(1e4) dp = [1] * (MAX + 1) for i in range(MAX // a + 1): for j in range(MAX // b + 1): if a * i + b * j <= MAX: dp[a * i + b * j] = 0 print(sum(dp))