w = int(input()) d = int(input()) for i in range(d - 1): a = w // (d ** 2) w -= a d -= 1 print(w)