w,d = [int(input()) for _ in range(2)] while d>1: power=w//(d*d) w-=power d-=1 print(w)