W = int(input())
D = int(input())

for i in range(D-1):
    y = W//(D-i)**2
    W -= y

print(W)