# import sys; input = sys.stdin.buffer.readline # sys.setrecursionlimit(10**7) from collections import defaultdict con = 10 ** 9 + 7; INF = float("inf") from fractions import gcd def getlist(): return list(map(int, input().split())) #処理内容 def main(): A, B = getlist() GCD = gcd(A, B) if GCD != 1: print(-1) return DP = [0] * 10001 DP[0] = 1 for i in range(10001): if DP[i] == 1: if i + A <= 10000: DP[i + A] = 1 if i + B <= 10000: DP[i + B] = 1 ans = 0 for i in range(10001): if DP[i] == 0: ans += 1 print(ans) if __name__ == '__main__': main()