def main(): w = int(input()) d = int(input()) rest_w = w while d > 0: pow = int(rest_w / d**2) rest_w = rest_w - pow d -= 1 print(rest_w) if __name__ == "__main__": main()