M,N=map(int,input().split()) ANS=0 while N!=M: x=(M-1)//N ANS+=x M-=x*N if M