W = int(input()) D = int(input()) while D > 1: wl = W // D ** 2 W -= wl D -= 1 print(W)