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