using System; using System.Collections.Generic; namespace Procon { class MainClass { static int popCount(int v) { int count = 0; while (v > 0) { if (v % 2 == 1) { count++; } v /= 2; } return count; } public static void Main(string[] args) { int N = int.Parse(Console.ReadLine()); bool[] check = new bool[N + 1]; List current = new List(); current.Add(1); check[1] = true; int turn = 1; while (current.Count > 0) { List next = new List(); foreach (var cur in current) { var count = popCount(cur); int nextR = cur + count; int nextL = cur - count; if (nextR == N) { Console.WriteLine(turn+1); return; } if (0 < nextR && nextR < N) { if (!check[nextR]) { next.Add(nextR); check[nextR] = true; } } if (0 < nextL && nextL < N) { if (!check[nextL]) { next.Add(nextL); check[nextL] = true; } } } turn++; current = next; } Console.WriteLine(-1); } } }