W= int(input()) D= int(input()) for i in range(D): today_W= W // (D**2) W= W - today_W print(W)