#include #include #include #include #include #include #include #include #include using namespace std; bool used[10001]; int now_bit(int num) { if(used[num]) return -1; bitset<8> bs(num); used[num] = true; return bs.count(); } int main() { int n; cin >> n; int pos = 1; int count = 1; while(pos != n) { int num = now_bit(pos); if(num == -1) { cout << -1 << endl; return 0; } else if(pos + num > n) { pos -= num; } else { pos += num; } ++count; } cout << count << endl; }