using System; using System.Collections.Generic; using System.Linq; namespace No003_ビットすごろく { class Program { static private List Number = new List(); static private int N; static void Main(string[] args) { N = int.Parse(Console.ReadLine()); bool[] progression = new bool[N + 1]; Search(1, 1, progression); if (Number.Count == 0) Console.WriteLine(-1); else Console.WriteLine(Number.Min()); } static void Search(int level, int count, bool[] progression) { if (level == N) { Number.Add(count); return; } else if (level < 1 || level > N || progression[level]) { return; } else { progression[level] = true; Search(level + BitNumber(level), count + 1, progression); Search(level - BitNumber(level), count + 1, progression); } } static int BitNumber(int a) { int temp = 0; do { temp += a % 2; a /= 2; } while (a > 0); return temp; } } }