using System; class sample{ public static void Main() { long n = long.Parse(Console.ReadLine()); long w = long.Parse(Console.ReadLine()); long a; while (w > 0) { a = n / (w * w); w--; if (w != 0) { n = n - a; } } Console.WriteLine(n); } }