using System; namespace No3 { class Program { private static int N; private static bool[] map; static void Main(string[] args) { N = int.Parse(Console.ReadLine()); map = new bool[N]; var result = Rec(0); Console.Write(result); } static int Rec(int index) { if (index == N - 1) return 1; if (index < 0) return -1; if (index >= N) return -1; if (map[index]) return -1; map[index] = true; var count = 0; for (var i = 0; i < 32; i++) { var tmp = 1 << i; if ((index + 1 & tmp) != 0) count++; } var front = Rec(index + count); var back = Rec(index - count); if (front == -1) { return back == -1 ? -1 : back + 1; } else { return back == -1 ? front + 1 : Math.Min(front, back) + 1; } } } }