using System; using System.Collections.Generic; namespace BitSugorokuCS { class Program { static int CountBit(int x) { int ret = 0; while (x >0) { x &= x - 1; ++ret; } return ret; } static int BitSugoroku(int N) { int[] D = new int[N+1]; D[1] = 1; Queue q = new Queue(); q.Enqueue(1); while(q.Count > 0) { int v_now = q.Dequeue(); if(v_now == N) { return D[v_now]; } int bitcount = CountBit(v_now); int v_rear = v_now + bitcount; int v_front = v_now - bitcount; if(0< v_rear && v_rear <=N && D[v_rear] == 0) { q.Enqueue(v_rear); D[v_rear] = D[v_now] + 1; } if (0 < v_front && v_front <= N && D[v_front] == 0) { q.Enqueue(v_front); D[v_front] = D[v_now] + 1; } } return -1; } static void Main(string[] args) { int N = int.Parse(Console.ReadLine()); Console.WriteLine(BitSugoroku(N)); } } }