#include #include inline int getInt(){ int s; scanf("%d", &s); return s; } #include using namespace std; int main(){ const int n = getInt(); vector dp(n); dp[0] = 1; queue q; q.push(0); while(q.size()){ const int m = q.front(); q.pop(); const int k = __builtin_popcount(m + 1); auto f = [&](int pos){ if(0 <= pos && pos < n && dp[pos] == 0){ dp[pos] = dp[m] + 1; q.push(pos); } }; f(m - k); f(m + k); } printf("%d\n", dp[n - 1] == 0 ? -1 : dp[n - 1]); return 0; }