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