import sys input=lambda:sys.stdin.readline().rstrip() W,D=[int(input()) for i in range(2)] while D>1: W,D=max(0,W-W//(D**2)),D-1 print(W)