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