w = int(input()) d = int(input()) while d-1 > 0: y = w//d**2 w -= y d -= 1 print(w)