using System.Numerics; public class Program { public static void Main() { //BigInteger num = BigInteger.Parse(Console.ReadLine() ?? string.Empty); int num = int.Parse(Console.ReadLine() ?? string.Empty); //string[] moji = (Console.ReadLine() ?? string.Empty).Trim().Split(' '); //string str = Console.ReadLine() ?? string.Empty; int count = 1; int math = 1; int numnum = math; for(int i = 0;i <= num;i++) { count++; string nn = Convert.ToString(math, 2); nn = nn.Replace("0", ""); if(nn.Length >= num+1) { Console.WriteLine(-1); } if(math + nn.Length == num) { Console.WriteLine(count); return; } if(math + nn.Length > num) { if (math -nn.Length == numnum||math-nn.Length <= 0) { Console.WriteLine(-1); return; } numnum = math; math-=nn.Length; } else { numnum = math; math += nn.Length; } } Console.WriteLine(-1); } }