import math W=float(input()) D=float(input()) while W>0: D*=D W1=math.floor(W/D) W-=W1 D-=1 print (W1)