using System; using System.Collections.Generic; namespace No3_3{ public class Program{ public static void Main(string[] args){ Console.WriteLine(Function(int.Parse(Console.ReadLine()))); } public static int Function(int n){ var que = new Queue(); var result = new int[n + 1]; que.Enqueue(1); result[1] = 1; while(que.Count > 0){ var place = que.Dequeue(); int move = 0, tmp = place; while(true){ if(tmp % 2 == 1) move++; if((tmp /= 2) == 0) break; } if(place + move <= n && result[place + move] == 0){ result[place + move] = result[place] + 1; que.Enqueue(place + move); } if(1 <= place - move && result[place - move] == 0){ result[place - move] = result[place] + 1; que.Enqueue(place - move); } } return result[n] == 0 ? -1 : result[n]; } } }