N, D = map(int, input().split()) a, b = N, D while b > 0: a, b = b, a%b print(N//a-1)