W = int(input()) D = int(inout()) dp = W // D ** 2 print(W - dp * D)