# -*- coding: utf-8 -*- def euclidean(a,b): if a < b: temp = a a = b b = temp while b>0: r = a % b a = b b = r return a N,D = map(int, input().split()) gcd = euclidean(N,D) if gcd == 1: print(N-1) else: print((N-1)//D)