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