#include #include #include #include #include #include bool search1(long N, long* d, bool* history, long depth, long limit, long p) { if( N == p ) { return true; } if( limit <= depth ) { return false; } if( 1 <= p + d[p] && p + d[p] <= N && history[p + d[p]] == false) { history[p] = true; if( search1(N, d, history, depth+1, limit, p + d[p]) ) { return true; } history[p] = false; } if( 1 <= p - d[p] && p - d[p] <= N && history[p - d[p]] == false ) { history[p] = true; if( search1(N, d, history, depth+1, limit, p - d[p]) ) { return true; } history[p] = false; } return false; } 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 d[11000] = {}; bool history[11000]; std::cin >> N; for(i = 1; i <= N; i++) { count = 0; temp = i; while( temp != 0 ) { count += (temp & 0x01); temp >>= 1; } d[i] = count; history[i] = false; } for(i = 1; i <= N; i++) { if( search1(N, d, history, 1, i, 1) ) { std::cout << i << std::endl; return 0; } } std::cout << "-1" << std::endl; return 0; }