import sys input=lambda: sys.stdin.readline().rstrip() def gcd(a,b): while b: a,b=b,a%b return a n,d=map(int,input().split()) print(n//gcd(n,d)-1)