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