using System; using System.Linq; namespace No3 { class Program { private static int N; private static int[] map; static void Main(string[] args) { N = int.Parse(Console.ReadLine()); map = Enumerable.Repeat(-1, N).ToArray(); Rec(0, 0); Console.Write(map.Last()); } static void Rec(int index, int preventCount) { if (index < 0) return; if (index >= N) return; if (map[index] != -1 && map[index] <= preventCount + 1) return; map[index] = preventCount + 1; if (index == N - 1) return; var bitcount = BitCount(index + 1); Rec(index + bitcount, preventCount + 1); Rec(index - bitcount, preventCount + 1); } static int BitCount(int value) { var count = 0; for (var i = 0; i < 32; i++) { var tmp = 1 << i; if ((value & tmp) != 0) count++; } return count; } } }