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