import math W = int(input()) D = int(input()) d = math.floor(math.sqrt(W)) d = min(d, D) for i in range(d, 1, -1): W -= W // i**2 print(W)