using System; namespace yukicoder { class Program { static int IceBoxCount, ResultBuyCount; 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]); string hitStr = str2; int count = 0; int buyCount = 0; while (count < ResultBuyCount) { count++; CountUp(hitStr, ref count); buyCount++; } Console.WriteLine(buyCount); Console.ReadLine(); } static void CountUp(string hitStr, ref int count) { if (count > ResultBuyCount) return; var index = (count - 1) % hitStr.Length; var hitChar = hitStr[index]; switch (hitChar) { case '1': count++; CountUp(hitStr, ref count); break; case '2': count++; CountUp(hitStr, ref count); count++; CountUp(hitStr, ref count); break; } } } }