W= int(input()) D= int(input()) for i in range(D+1): if D > 1: today_W= W // (D**2) W= W - today_W else: break print(W)