#include #include #include #include #include #include int main() { /* default begin */ long i, j, k; long n, m; long temp; long t; std::vector v; bool b; /* default end */ long N; long count; long d1[11000] = {}; long d2[11000] = {}; std::cin >> N; for(i = 1; i <= N; i++) { count = 0; temp = i; while( temp != 0 ) { count += (temp & 0x01); temp >>= 1; } d1[i] = count; d2[i] = -1; } d2[1] = 0; for(i = 0; i < N; i++) { b = true; for(j = 1; j <= N; j++) { if( d2[j] == i ) { b = false; temp = j + d1[j]; if( 1 <= temp && temp <= N ) { if( d2[temp] == -1 ) { d2[temp] = i+1; if( temp == N ) { goto label_1; } } } temp = j - d1[j]; if( 1 <= temp && temp <= N ) { if( d2[temp] == -1 ) { d2[temp] = i+1; if( temp == N ) { goto label_1; } } } } } if( b ) { break; } } std::cout << "-1" << std::endl; return 0; label_1: std::cout << d2[temp] + 1 << std::endl; return 0; }