using System; using System.Collections.Generic; namespace Problem003 { class Program { static void Main(string[] args) { var n = int.Parse(Console.ReadLine()); Console.WriteLine(Process(n, 1, new HashSet())); } static int Process(int n, int pos, HashSet db, int depth = 1) { if (db.Contains(pos)) return -1; db.Add(pos); if (pos == n) return depth; var steps = Count1(pos); // 前に移動 var next = pos + steps; if (next <= n) { var ans = Process(n, next, db, depth + 1); if (ans > 0) return ans; } // 後ろに移動 next = pos - steps; if (next > 1) { var ans = Process(n, next, db, depth + 1); if (ans > 0) return ans; } return -1; } static int Count1(int v) { var count = 0; while (v != 0) { if ((v & 1) == 1) count++; v >>= 1; } return count; } } }