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