import java.util.*; public class Test38{ public static void main(String[] args) { Scanner sc = new Scanner(System.in); int W = sc.nextInt(); int D = sc.nextInt(); int Yaruki; for(int i=D; i>1; i--){ Yaruki = W/(D*D); W -= Yaruki; } System.out.println(W); } }