using System; using System.Collections.Generic; using System.Linq; public class Amatsuki{ public static void Main(){ var target = int.Parse(Console.ReadLine()); var pass = new int[0]; var result = new List(); check(1, target, pass, ref result); if(result.Any()){ Console.WriteLine(result.Count); } else{ Console.WriteLine(-1); } } public static void check(int now, int target, int[] pass, ref List result){ var passList = pass.ToList(); passList.Add(now); if(now == target && passList.Count < result.Count){ result = passList; } if(passList.Contains(now)){ return; } var bit = bitCount(now); if(now + bit <= target){ check(now + bit, target, passList.ToArray(), ref result); } if(now - bit > 1){ check(now - bit, target, passList.ToArray(), ref result); } } public static int bitCount(int dec){ var result = 0; while(dec > 0){ if(dec % 2 == 1){ result++; } dec /= 2; } return result; } }