using System; namespace Yuki { class Program { static void Main(string[] args) { string[] ss = Console.ReadLine().Split(); int n = int.Parse(ss[0]); int k = int.Parse(ss[1]); int[] h = new int[5]; int f = (n - 1) % (k + 1); for (int i = 0; i < 5; i++) { h[i] = f + (k + 1) * i; } int s = 0; if (h[0] == 0) { Console.WriteLine("0"); s = 1; } for (int i = s; i < h.Length; i++) { if (int.Parse(Console.ReadLine()) >= n) break; else Console.WriteLine(h[i]); } } } }