using System; namespace yukicoder { class Program { static int IceBoxCount, ResultBuyCount; static string HitString; static void Main(string[] args) { string str = Console.ReadLine(); string str2 = Console.ReadLine(); string[] strs = str.Split(' '); IceBoxCount = int.Parse(strs[0]); ResultBuyCount = int.Parse(strs[1]); HitString = str2; int count = 0; int buyCount = 0; while (count < ResultBuyCount) { buyCount++; int stackCount = 1; do { count++; stackCount--; var index = (count - 1) % HitString.Length; stackCount += int.Parse(HitString[index].ToString()); } while (stackCount > 0 && count < ResultBuyCount); } Console.WriteLine(buyCount); Console.ReadLine(); } static void CountUp(ref int count) { if (count > ResultBuyCount) return; var index = (count - 1) % HitString.Length; var hitChar = HitString[index]; switch (hitChar) { case '1': count++; CountUp(ref count); break; case '2': count++; CountUp(ref count); count++; CountUp(ref count); break; } } } }