N,d=map(int,input().split()) n=N while d:n,d=d,n%d print(N//n-1)